Repository: kubernetes/kubernetes
File: staging/src/k8s.io/dynamic-resource-allocation/api/v1beta2/conversion_test.go (Go)

Code before:
			err := scheme.Convert(tc.in, tc.out, nil)
			if err != nil {
				if len(tc.expectErr) == 0 {
					t.Fatalf("unexpected error %v", err)
				}
				if !strings.Contains(err.Error(), tc.expectErr) {
					t.Fatalf("expected error %s, got %v", tc.expectErr, err)
				}
				return
			}
			if len(tc.expectErr) > 0 {
				t.Fatalf("expected error %s, got none", tc.expectErr)
			}
			if !reflect.DeepEqual(tc.out, tc.expectOut) {
				t.Fatalf("unexpected result:\n %s", cmp.Diff(tc.expectOut, tc.out))
			}
		})
	}

}

// TestConversionRoundTrip verifies that the automatically generated and
// hand-written conversion code for the DRA API correctly round-trips
// between v1beta2 and v1. For each non-list type registered in v1beta2,
// a fuzzed object is converted to v1 and back, and the result must be
// equal to the original.
func TestConversionRoundTrip(t *testing.T) {
	scheme := runtime.NewScheme()
	if err := resourceapi.AddToScheme(scheme); err != nil {
		t.Fatal(err)
	}
	if err := resourcev1beta2.AddToScheme(scheme); err != nil {
		t.Fatal(err)
	}
	if err := AddToScheme(scheme); err != nil {
		t.Fatal(err)
	}

	filler := apitest.NewFiller(t, scheme, nil)

	apitest.ConversionRoundTrip(t, scheme, filler,
		schema.GroupVersion{Group: resourcev1beta2.GroupName, Version: "v1beta2"},
		schema.GroupVersion{Group: resourceapi.GroupName, Version: "v1"},
	)
}


Review comment (suggestion):
```suggestion
// equal to the original.
//
// Note that this only covers conversion code which is called
// while converting the top-level API types. Types embedded
// inside those have their own conversion functions, but those
// are not necessarily called.
```

Code after:
			err := scheme.Convert(tc.in, tc.out, nil)
			if err != nil {
				if len(tc.expectErr) == 0 {
					t.Fatalf("unexpected error %v", err)
				}
				if !strings.Contains(err.Error(), tc.expectErr) {
					t.Fatalf("expected error %s, got %v", tc.expectErr, err)
				}
				return
			}
			if len(tc.expectErr) > 0 {
				t.Fatalf("expected error %s, got none", tc.expectErr)
			}
			if !reflect.DeepEqual(tc.out, tc.expectOut) {
				t.Fatalf("unexpected result:\n %s", cmp.Diff(tc.expectOut, tc.out))
			}
		})
	}

}

// TestConversionRoundTrip verifies that the automatically generated and
// hand-written conversion code for the DRA API correctly round-trips
// between v1beta2 and v1. For each non-list type registered in v1beta2,
// a fuzzed object is converted to v1 and back, and the result must be
// equal to the original.
//
// Note that this only covers conversion code which is called
// while converting the top-level API types. Types embedded
// inside those have their own conversion functions, but those
// are not necessarily called.
func TestConversionRoundTrip(t *testing.T) {
	scheme := runtime.NewScheme()
	if err := resourceapi.AddToScheme(scheme); err != nil {
		t.Fatal(err)
	}
	if err := resourcev1beta2.AddToScheme(scheme); err != nil {
		t.Fatal(err)
	}
	if err := AddToScheme(scheme); err != nil {
		t.Fatal(err)
	}

	filler := apitest.NewFiller(t, scheme, nil)

	apitest.ConversionRoundTrip(t, scheme, filler,
		schema.GroupVersion{Group: resourcev1beta2.GroupName, Version: "v1beta2"},
		schema.GroupVersion{Group: resourceapi.GroupName, Version: "v1"},
	)
}