volcano.sh/volcano@v1.9.0/pkg/cli/vcancel/cancel_test.go (about) 1 /* 2 Copyright 2019 The Volcano 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 vcancel 18 19 import ( 20 "encoding/json" 21 "net/http" 22 "net/http/httptest" 23 "testing" 24 25 "github.com/spf13/cobra" 26 27 "volcano.sh/apis/pkg/apis/batch/v1alpha1" 28 ) 29 30 func TestCancelJobJob(t *testing.T) { 31 response := v1alpha1.Job{} 32 response.Name = "testJob" 33 34 handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 35 w.Header().Set("Content-Type", "application/json") 36 val, err := json.Marshal(response) 37 if err == nil { 38 w.Write(val) 39 } 40 41 }) 42 43 server := httptest.NewServer(handler) 44 defer server.Close() 45 46 cancelJobFlags.Master = server.URL 47 cancelJobFlags.Namespace = "test" 48 cancelJobFlags.JobName = "testJob" 49 50 testCases := []struct { 51 Name string 52 ExpectValue error 53 }{ 54 { 55 Name: "CancelJob", 56 ExpectValue: nil, 57 }, 58 } 59 60 for i, testcase := range testCases { 61 err := CancelJob() 62 if err != nil { 63 t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.ExpectValue, err) 64 } 65 } 66 67 } 68 69 func TestInitDeleteFlags(t *testing.T) { 70 var cmd cobra.Command 71 InitCancelFlags(&cmd) 72 73 if cmd.Flag("namespace") == nil { 74 t.Errorf("Could not find the flag namespace") 75 } 76 if cmd.Flag("name") == nil { 77 t.Errorf("Could not find the flag name") 78 } 79 80 }