github.com/projectriff/riff-cli@v0.0.5-0.20180301104501-5db7a3bd9fc1/cmd/delete_command_test.go (about) 1 /* 2 * Copyright 2018 the original author or 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 cmd 18 19 import ( 20 "testing" 21 "github.com/stretchr/testify/assert" 22 "github.com/projectriff/riff-cli/pkg/osutils" 23 "github.com/projectriff/riff-cli/pkg/options" 24 ) 25 26 func TestDeleteCommandImplicitPath(t *testing.T) { 27 clearDeleteOptions() 28 as := assert.New(t) 29 rootCmd.SetArgs([]string{"delete", "--dry-run", osutils.Path("../test_data/shell/echo")}) 30 31 _, err := rootCmd.ExecuteC() 32 as.NoError(err) 33 as.Equal("../test_data/shell/echo", DeleteAllOptions.FilePath) 34 as.Equal("default", DeleteAllOptions.Namespace) 35 } 36 37 func TestDeleteCommandExplicitPath(t *testing.T) { 38 clearDeleteOptions() 39 as := assert.New(t) 40 rootCmd.SetArgs([]string{"delete", "--dry-run", "-f", osutils.Path("../test_data/shell/echo")}) 41 42 _, err := rootCmd.ExecuteC() 43 as.NoError(err) 44 as.Equal("../test_data/shell/echo", DeleteAllOptions.FilePath) 45 as.Equal("default", DeleteAllOptions.Namespace) 46 } 47 48 func TestDeleteCommandExplicitFile(t *testing.T) { 49 clearDeleteOptions() 50 as := assert.New(t) 51 rootCmd.SetArgs([]string{"delete", "--dry-run", "-f", osutils.Path("../test_data/shell/echo/echo-topics.yaml")}) 52 53 _, err := rootCmd.ExecuteC() 54 as.NoError(err) 55 as.Equal("../test_data/shell/echo/echo-topics.yaml", DeleteAllOptions.FilePath) 56 as.Equal("default", DeleteAllOptions.Namespace) 57 } 58 59 func TestDeleteCommandWithName(t *testing.T) { 60 clearDeleteOptions() 61 as := assert.New(t) 62 rootCmd.SetArgs([]string{"delete", "--dry-run", "--name", "square"}) 63 64 _, err := rootCmd.ExecuteC() 65 as.NoError(err) 66 as.Equal("square", DeleteAllOptions.FunctionName) 67 } 68 69 func TestDeleteCommandAllFlag(t *testing.T) { 70 clearDeleteOptions() 71 as := assert.New(t) 72 rootCmd.SetArgs([]string{"delete", "--dry-run", "-f", osutils.Path("../test_data/shell/echo"), "--all"}) 73 74 _, err := rootCmd.ExecuteC() 75 as.NoError(err) 76 as.Equal("../test_data/shell/echo", DeleteAllOptions.FilePath) 77 as.Equal(true, DeleteAllOptions.All) 78 as.Equal("default", DeleteAllOptions.Namespace) 79 } 80 81 func TestDeleteCommandWithNamespace(t *testing.T) { 82 clearDeleteOptions() 83 as := assert.New(t) 84 rootCmd.SetArgs([]string{"delete", "--dry-run", "--namespace", "test-test", "-f", osutils.Path("../test_data/shell/echo/")}) 85 86 _, err := rootCmd.ExecuteC() 87 as.NoError(err) 88 as.Equal("../test_data/shell/echo", DeleteAllOptions.FilePath) 89 as.Equal("test-test", DeleteAllOptions.Namespace) 90 } 91 92 func clearDeleteOptions() { 93 DeleteAllOptions = options.DeleteAllOptions{} 94 }