Esempio n. 1
0
// call implements the bulk of the lease.Client interface.
func (client *Client) call(method string, args []interface{}) error {
	select {
	case <-client.done:
		return errors.Errorf("Client method called after test complete: %s %v", method, args)
	default:
		defer func() {
			if len(client.expect) == 0 || client.failed != "" {
				close(client.done)
			}
		}()
	}

	expect := client.expect[0]
	client.expect = client.expect[1:]
	if expect.callback != nil {
		expect.callback(client.leases)
	}

	if method == expect.method {
		if ok, _ := jc.DeepEqual(args, expect.args); ok {
			return expect.err
		}
	}
	client.failed = fmt.Sprintf("unexpected Client call:\n  actual: %s %v\n  expect: %s %v",
		method, args, expect.method, expect.args,
	)
	return errors.New(client.failed)
}
Esempio n. 2
0
func TestOrigin(t *testing.T) {
	srcMap := make(map[interface{}]interface{})
	withOriginMap := make(map[interface{}]interface{})
	if err := yaml.Unmarshal([]byte(merged), srcMap); err != nil {
		t.Fatalf("failed to unmarshal %s: %s", "merged", err)
	}
	if err := yaml.Unmarshal([]byte(withOrigin), withOriginMap); err != nil {
		t.Fatalf("failed to unmarshal %s: %s", "withOrigin", err)
	}
	Origin(srcMap, "origin")
	if _, err := checkers.DeepEqual(withOriginMap, srcMap); err != nil {
		t.Error(err)
	}
}
Esempio n. 3
0
func TestDeepEqual(t *testing.T) {
	for _, test := range deepEqualTests {
		r, err := checkers.DeepEqual(test.a, test.b)
		if r != test.eq {
			t.Errorf("deepEqual(%v, %v) = %v, want %v", test.a, test.b, r, test.eq)
		}
		if test.eq {
			if err != nil {
				t.Errorf("deepEqual(%v, %v): unexpected error message %q when equal", test.a, test.b, err)
			}
		} else {
			if ok, _ := regexp.MatchString(test.msg, err.Error()); !ok {
				t.Errorf("deepEqual(%v, %v); unexpected error %q, want %q", test.a, test.b, err.Error(), test.msg)
			}
		}
	}
}
Esempio n. 4
0
func TestMerge(t *testing.T) {
	srcMap := make(map[interface{}]interface{})
	dstMap := make(map[interface{}]interface{})
	mergedMap := make(map[interface{}]interface{})
	if err := yaml.Unmarshal([]byte(src), srcMap); err != nil {
		t.Fatalf("failed to unmarshal %s: %s", "src", err)
	}
	if err := yaml.Unmarshal([]byte(dst), dstMap); err != nil {
		t.Fatalf("failed to unmarshal %s: %s", "dst", err)
	}
	if err := yaml.Unmarshal([]byte(merged), mergedMap); err != nil {
		t.Fatalf("failed to unmarshal %s: %s", "merged", err)
	}
	Merge(dstMap, srcMap)
	if _, err := checkers.DeepEqual(mergedMap, dstMap); err != nil {
		t.Error(err)
	}
}
Esempio n. 5
0
func deepEqual(a1, a2 interface{}) bool {
	ok, _ := checkers.DeepEqual(a1, a2)
	return ok
}
Esempio n. 6
0
// AssertDeepEqual fails the test if the two objects do not pass reflect.DeepEqual.
func AssertDeepEqual(t *testing.T, a, b interface{}) {
	if eq, err := checkers.DeepEqual(a, b); !eq {
		t.Fatal(err)
	}
}