func TestDumpSortedKeys(t *testing.T) { cfg := spew.ConfigState{SortKeys: true} s := cfg.Sdump(map[int]string{1: "1", 3: "3", 2: "2"}) expected := `(map[int]string) (len=3) { (int) 1: (string) (len=1) "1", (int) 2: (string) (len=1) "2", (int) 3: (string) (len=1) "3" } ` if s != expected { t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) } }
// ObjectGoPrintSideBySide prints a and b as textual dumps side by side, // enabling easy visual scanning for mismatches. func ObjectGoPrintSideBySide(a, b interface{}) string { s := spew.ConfigState{ Indent: " ", // Extra deep spew. DisableMethods: true, } sA := s.Sdump(a) sB := s.Sdump(b) linesA := strings.Split(sA, "\n") linesB := strings.Split(sB, "\n") width := 0 for _, s := range linesA { l := len(s) if l > width { width = l } } for _, s := range linesB { l := len(s) if l > width { width = l } } buf := &bytes.Buffer{} w := tabwriter.NewWriter(buf, width, 0, 1, ' ', 0) max := len(linesA) if len(linesB) > max { max = len(linesB) } for i := 0; i < max; i++ { var a, b string if i < len(linesA) { a = linesA[i] } if i < len(linesB) { b = linesB[i] } fmt.Fprintf(w, "%s\t%s\n", a, b) } w.Flush() return buf.String() }
func TestImportImageQuayIO(t *testing.T) { rt, _ := kclient.TransportFor(&kclient.Config{}) importCtx := importer.NewContext(rt).WithCredentials(importer.NoCredentials) imports := &api.ImageStreamImport{ Spec: api.ImageStreamImportSpec{ Images: []api.ImageImportSpec{ {From: kapi.ObjectReference{Kind: "DockerImage", Name: "quay.io/coreos/etcd"}}, }, }, } i := importer.NewImageStreamImporter(importCtx, 3, nil) if err := i.Import(gocontext.Background(), imports); err != nil { t.Fatal(err) } if imports.Status.Repository != nil { t.Errorf("unexpected repository: %#v", imports.Status.Repository) } if len(imports.Status.Images) != 1 { t.Fatalf("unexpected response: %#v", imports.Status.Images) } d := imports.Status.Images[0] if d.Status.Status != unversioned.StatusSuccess { if d.Status.Reason == "NotV2Registry" { t.Skipf("the server did not report as a v2 registry: %#v", d.Status) } t.Fatalf("unexpected error: %#v", d.Status) } if d.Image == nil || len(d.Image.DockerImageManifest) == 0 || !strings.HasPrefix(d.Image.DockerImageReference, "quay.io/coreos/etcd@") || len(d.Image.DockerImageMetadata.ID) == 0 || len(d.Image.DockerImageLayers) == 0 { t.Errorf("unexpected object: %#v", d.Image) s := spew.ConfigState{ Indent: " ", // Extra deep spew. DisableMethods: true, } t.Logf("import: %s", s.Sdump(d)) } }
func TestDumpSortedKeys(t *testing.T) { cfg := spew.ConfigState{SortKeys: true} s := cfg.Sdump(map[int]string{1: "1", 3: "3", 2: "2"}) expected := "(map[int]string) (len=3) {\n(int) 1: (string) (len=1) " + "\"1\",\n(int) 2: (string) (len=1) \"2\",\n(int) 3: (string) " + "(len=1) \"3\"\n" + "}\n" if s != expected { t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) } s = cfg.Sdump(map[stringer]int{"1": 1, "3": 3, "2": 2}) expected = "(map[spew_test.stringer]int) (len=3) {\n" + "(spew_test.stringer) (len=1) stringer 1: (int) 1,\n" + "(spew_test.stringer) (len=1) stringer 2: (int) 2,\n" + "(spew_test.stringer) (len=1) stringer 3: (int) 3\n" + "}\n" if s != expected { t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) } s = cfg.Sdump(map[pstringer]int{pstringer("1"): 1, pstringer("3"): 3, pstringer("2"): 2}) expected = "(map[spew_test.pstringer]int) (len=3) {\n" + "(spew_test.pstringer) (len=1) stringer 1: (int) 1,\n" + "(spew_test.pstringer) (len=1) stringer 2: (int) 2,\n" + "(spew_test.pstringer) (len=1) stringer 3: (int) 3\n" + "}\n" if spew.UnsafeDisabled { expected = "(map[spew_test.pstringer]int) (len=3) {\n" + "(spew_test.pstringer) (len=1) \"1\": (int) 1,\n" + "(spew_test.pstringer) (len=1) \"2\": (int) 2,\n" + "(spew_test.pstringer) (len=1) \"3\": (int) 3\n" + "}\n" } if s != expected { t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) } s = cfg.Sdump(map[customError]int{customError(1): 1, customError(3): 3, customError(2): 2}) expected = "(map[spew_test.customError]int) (len=3) {\n" + "(spew_test.customError) error: 1: (int) 1,\n" + "(spew_test.customError) error: 2: (int) 2,\n" + "(spew_test.customError) error: 3: (int) 3\n" + "}\n" if s != expected { t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) } }
func TestDumpSortedKeys(t *testing.T) { cfg := spew.ConfigState{SortKeys: true} s := cfg.Sdump(map[int]string{1: "1", 3: "3", 2: "2"}) expected := `(map[int]string) (len=3) { (int) 1: (string) (len=1) "1", (int) 2: (string) (len=1) "2", (int) 3: (string) (len=1) "3" } ` if s != expected { t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) } s = cfg.Sdump(map[stringer]int{"1": 1, "3": 3, "2": 2}) expected = `(map[spew_test.stringer]int) (len=3) { (spew_test.stringer) (len=1) stringer 1: (int) 1, (spew_test.stringer) (len=1) stringer 2: (int) 2, (spew_test.stringer) (len=1) stringer 3: (int) 3 } ` if s != expected { t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) } s = cfg.Sdump(map[pstringer]int{pstringer("1"): 1, pstringer("3"): 3, pstringer("2"): 2}) expected = `(map[spew_test.pstringer]int) (len=3) { (spew_test.pstringer) (len=1) stringer 1: (int) 1, (spew_test.pstringer) (len=1) stringer 2: (int) 2, (spew_test.pstringer) (len=1) stringer 3: (int) 3 } ` if s != expected { t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) } s = cfg.Sdump(map[customError]int{customError(1): 1, customError(3): 3, customError(2): 2}) expected = `(map[spew_test.customError]int) (len=3) { (spew_test.customError) error: 1: (int) 1, (spew_test.customError) error: 2: (int) 2, (spew_test.customError) error: 3: (int) 3 } ` if s != expected { t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) } }