import ( "net/http/httptest" "testing" "k8s.io/kube-aggregator/pkg/apis/apiregistration/validation" "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" utilvalidation "k8s.io/kube-aggregator/pkg/util/validation" ) func TestValidateValidAPIServiceSpec(t *testing.T) { fakeHandler := &util.FakeHandler{StatusCode: 200} fakeHandler.Responses = append(fakeHandler.Responses, []byte(` {"kind": "APIService", "status": {"conditions": [{"type": "Available", "status": "True"}]}} `)) fakeServer := httptest.NewServer(fakeHandler) defer fakeServer.Close() client := validation.NewClient(fakeServer.URL, "/", nil) err := utilvalidation.Validate(context.TODO(), &v1.APIService{ ObjectMeta: metav1.ObjectMeta{Name: "test"}, Spec: v1.APIServiceSpec{ Group: "group", Version: "v1", GroupPriorityMinimum: 100, Service: &v1.ServiceReference{ Namespace: "default", Name: "test", }, }, }, client) if err != nil { t.Fatalf("Unexpected error validating valid APIService: %v", err) } }In the above example, a valid `APIService` object is passed to `utilvalidation.Validate` function which does a few validation checks. The fake server is created using `FakeHandler` and its responses are set to simulate an available `APIService`. This simulated response is then passed to the `validation.NewClient` function which returns a client that actually interacts with the fake server. This client is then passed to the `utilvalidation.Validate` function to simulate the validation of the `APIService`.