https://github.com/google/cayley
Raw File
Tip revision: c33467000f64158c88c3031d221e5d21b504aa66 authored by Barak Michener on 12 April 2017, 19:19:41 UTC
Merge pull request #555 from barakmich/releng
Tip revision: c334670
quadwriter_test.go
package graph

import (
	"errors"
	"testing"
)

func TestIsQuadExist(t *testing.T) {
	tests := []struct {
		Err     error
		Matches bool
	}{
		{Err: nil, Matches: false},
		{Err: errors.New("foo"), Matches: false},
		{Err: ErrQuadExists, Matches: true},
		{Err: &DeltaError{Err: errors.New("foo")}, Matches: false},
		{Err: &DeltaError{Err: ErrQuadExists}, Matches: true},
	}

	for i, test := range tests {
		if match := IsQuadExist(test.Err); test.Matches != match {
			t.Errorf("%d> unexpected match: %t", i, match)
		}
	}
}

func TestIsQuadNotExist(t *testing.T) {
	tests := []struct {
		Err     error
		Matches bool
	}{
		{Err: nil, Matches: false},
		{Err: errors.New("foo"), Matches: false},
		{Err: ErrQuadNotExist, Matches: true},
		{Err: &DeltaError{Err: errors.New("foo")}, Matches: false},
		{Err: &DeltaError{Err: ErrQuadNotExist}, Matches: true},
	}

	for i, test := range tests {
		if match := IsQuadNotExist(test.Err); test.Matches != match {
			t.Errorf("%d> unexpected match: %t", i, match)
		}
	}
}

func TestIsInvalidAction(t *testing.T) {
	tests := []struct {
		Err     error
		Matches bool
	}{
		{Err: nil, Matches: false},
		{Err: errors.New("foo"), Matches: false},
		{Err: ErrInvalidAction, Matches: true},
		{Err: &DeltaError{Err: errors.New("foo")}, Matches: false},
		{Err: &DeltaError{Err: ErrInvalidAction}, Matches: true},
	}

	for i, test := range tests {
		if match := IsInvalidAction(test.Err); test.Matches != match {
			t.Errorf("%d> unexpected match: %t", i, match)
		}
	}
}
back to top