github.com/spinnaker/spin@v1.30.0/cmd/pipeline/delete_test.go (about) 1 // Copyright (c) 2018, Google, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package pipeline 16 17 import ( 18 "io/ioutil" 19 "testing" 20 21 "github.com/spinnaker/spin/cmd" 22 ) 23 24 // TODO(jacobkiefer): This test overlaps heavily with pipeline_save_test.go, 25 // consider factoring common testing code out. 26 func TestPipelineDelete_basic(t *testing.T) { 27 ts := testGateSuccess() 28 defer ts.Close() 29 30 rootCmd, rootOpts := cmd.NewCmdRoot(ioutil.Discard, ioutil.Discard) 31 pipelineCmd, _ := NewPipelineCmd(rootOpts) 32 rootCmd.AddCommand(pipelineCmd) 33 34 args := []string{"pipeline", "delete", "--application", "app", "--name", "one", "--gate-endpoint", ts.URL} 35 rootCmd.SetArgs(args) 36 err := rootCmd.Execute() 37 if err != nil { 38 t.Fatalf("Command failed with: %s", err) 39 } 40 } 41 42 func TestPipelineDelete_fail(t *testing.T) { 43 ts := testGateFail() 44 defer ts.Close() 45 46 rootCmd, rootOpts := cmd.NewCmdRoot(ioutil.Discard, ioutil.Discard) 47 pipelineCmd, _ := NewPipelineCmd(rootOpts) 48 rootCmd.AddCommand(pipelineCmd) 49 50 args := []string{"pipeline", "delete", "--application", "app", "--name", "one", "--gate-endpoint", ts.URL} 51 rootCmd.SetArgs(args) 52 err := rootCmd.Execute() 53 if err == nil { 54 t.Fatalf("Command failed with: %s", err) 55 } 56 } 57 58 func TestPipelineDelete_flags(t *testing.T) { 59 ts := testGateSuccess() 60 defer ts.Close() 61 62 rootCmd, rootOpts := cmd.NewCmdRoot(ioutil.Discard, ioutil.Discard) 63 pipelineCmd, _ := NewPipelineCmd(rootOpts) 64 rootCmd.AddCommand(pipelineCmd) 65 66 args := []string{"pipeline", "delete", "--gate-endpoint", ts.URL} // Missing pipeline app and name. 67 rootCmd.SetArgs(args) 68 err := rootCmd.Execute() 69 if err == nil { 70 t.Fatalf("Command failed with: %s", err) 71 } 72 } 73 74 func TestPipelineDelete_missingname(t *testing.T) { 75 ts := testGateSuccess() 76 defer ts.Close() 77 78 rootCmd, rootOpts := cmd.NewCmdRoot(ioutil.Discard, ioutil.Discard) 79 pipelineCmd, _ := NewPipelineCmd(rootOpts) 80 rootCmd.AddCommand(pipelineCmd) 81 82 args := []string{"pipeline", "delete", "--application", "app", "--gate-endpoint", ts.URL} 83 rootCmd.SetArgs(args) 84 err := rootCmd.Execute() 85 if err == nil { 86 t.Fatalf("Command errantly succeeded. %s", err) 87 } 88 } 89 90 func TestPipelineDelete_missingapp(t *testing.T) { 91 ts := testGateSuccess() 92 defer ts.Close() 93 94 rootCmd, rootOpts := cmd.NewCmdRoot(ioutil.Discard, ioutil.Discard) 95 pipelineCmd, _ := NewPipelineCmd(rootOpts) 96 rootCmd.AddCommand(pipelineCmd) 97 98 args := []string{"pipeline", "delete", "--name", "one", "--gate-endpoint", ts.URL} 99 rootCmd.SetArgs(args) 100 err := rootCmd.Execute() 101 if err == nil { 102 t.Fatalf("Command errantly succeeded. %s", err) 103 } 104 }