func compareJWTs(a, b jose.JWT) string { if a.Encode() == b.Encode() { return "" } var aClaims, bClaims jose.Claims for _, j := range []struct { claims *jose.Claims jwt jose.JWT }{ {&aClaims, a}, {&bClaims, b}, } { var err error *j.claims, err = j.jwt.Claims() if err != nil { *j.claims = jose.Claims(map[string]interface{}{ "msg": "bad claims", "err": err, }) } } return diff.ObjectDiff(aClaims, bClaims) }
func (t *testPersister) Persist(cfg map[string]string) error { if len(t.persists) == 0 { return errors.New("unexpected persist call") } var persist testPersist persist, t.persists = t.persists[0], t.persists[1:] if !reflect.DeepEqual(persist.cfg, cfg) { return fmt.Errorf("Unexpected cfg: %v", diff.ObjectDiff(persist.cfg, cfg)) } return persist.returnErr }
func (d *defaultCacheMutationDetector) CompareObjects() { d.lock.Lock() defer d.lock.Unlock() altered := false for i, obj := range d.cachedObjs { if !reflect.DeepEqual(obj.cached, obj.copied) { fmt.Printf("CACHE %s[%d] ALTERED!\n%v\n", d.name, i, diff.ObjectDiff(obj.cached, obj.copied)) altered = true } } if altered { msg := fmt.Sprintf("cache %s modified", d.name) if d.failureFunc != nil { d.failureFunc(msg) return } panic(msg) } }
func TestDoRequestFailed(t *testing.T) { status := &unversioned.Status{ Code: http.StatusNotFound, Status: unversioned.StatusFailure, Reason: unversioned.StatusReasonNotFound, Message: " \"\" not found", Details: &unversioned.StatusDetails{}, } expectedBody, _ := runtime.Encode(testapi.Default.Codec(), status) fakeHandler := utiltesting.FakeHandler{ StatusCode: 404, ResponseBody: string(expectedBody), T: t, } testServer := httptest.NewServer(&fakeHandler) defer testServer.Close() c, err := restClient(testServer) if err != nil { t.Fatalf("unexpected error: %v", err) } body, err := c.Get().Do().Raw() if err == nil || body != nil { t.Errorf("unexpected non-error: %#v", body) } ss, ok := err.(errors.APIStatus) if !ok { t.Errorf("unexpected error type %v", err) } actual := ss.Status() expected := *status // The decoder will apply the default Version and Kind to the Status. expected.APIVersion = "v1" expected.Kind = "Status" if !reflect.DeepEqual(&expected, &actual) { t.Errorf("Unexpected mis-match: %s", diff.ObjectDiff(status, &actual)) } }