k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/test/integration/apiserver/export_test.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package apiserver 18 19 import ( 20 "net/http" 21 "testing" 22 23 corev1 "k8s.io/api/core/v1" 24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 ) 26 27 // Tests that the apiserver rejects the export param 28 func TestExportRejection(t *testing.T) { 29 ctx, clientSet, _, tearDownFn := setup(t) 30 defer tearDownFn() 31 32 _, err := clientSet.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ 33 ObjectMeta: metav1.ObjectMeta{Name: "export-fail"}, 34 }, metav1.CreateOptions{}) 35 if err != nil { 36 t.Fatal(err) 37 } 38 defer func() { 39 if err := clientSet.CoreV1().Namespaces().Delete(ctx, "export-fail", metav1.DeleteOptions{}); err != nil { 40 t.Errorf("error whiling deleting the namespace, err: %v", err) 41 } 42 }() 43 44 result := clientSet.Discovery().RESTClient().Get().AbsPath("/api/v1/namespaces/export-fail").Param("export", "true").Do(ctx) 45 statusCode := 0 46 result.StatusCode(&statusCode) 47 if statusCode != http.StatusBadRequest { 48 t.Errorf("expected %v, got %v", http.StatusBadRequest, statusCode) 49 } 50 51 result = clientSet.Discovery().RESTClient().Get().AbsPath("/api/v1/namespaces/export-fail").Param("export", "false").Do(ctx) 52 statusCode = 0 53 result.StatusCode(&statusCode) 54 if statusCode != http.StatusOK { 55 t.Errorf("expected %v, got %v", http.StatusOK, statusCode) 56 } 57 }