|
| 1 | +// Copyright © 2025 Meroxa, 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 pipelines |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/matryer/is" |
| 22 | +) |
| 23 | + |
| 24 | +func TestInitExecutionNoArgs(t *testing.T) { |
| 25 | + is := is.New(t) |
| 26 | + |
| 27 | + c := InitCommand{} |
| 28 | + err := c.Args([]string{}) |
| 29 | + is.NoErr(err) |
| 30 | + is.Equal(defaultPipelineName, c.args.pipelineName) |
| 31 | +} |
| 32 | + |
| 33 | +func TestInitExecutionMultipleArgs(t *testing.T) { |
| 34 | + is := is.New(t) |
| 35 | + |
| 36 | + c := InitCommand{} |
| 37 | + err := c.Args([]string{"foo", "bar"}) |
| 38 | + is.True((err != nil)) |
| 39 | + is.Equal(err.Error(), "too many arguments") |
| 40 | +} |
| 41 | + |
| 42 | +func TestInitExecutionOneArg(t *testing.T) { |
| 43 | + is := is.New(t) |
| 44 | + |
| 45 | + pipelineName := "pipeline-name" |
| 46 | + |
| 47 | + c := InitCommand{} |
| 48 | + err := c.Args([]string{pipelineName}) |
| 49 | + is.NoErr(err) |
| 50 | + is.Equal(pipelineName, c.args.pipelineName) |
| 51 | +} |
| 52 | + |
| 53 | +func TestInit_getPipelineName(t *testing.T) { |
| 54 | + tests := []struct { |
| 55 | + name string |
| 56 | + argsPipelineName string |
| 57 | + flagsSource string |
| 58 | + flagsDestination string |
| 59 | + expected string |
| 60 | + }{ |
| 61 | + { |
| 62 | + name: "Custom pipeline name", |
| 63 | + argsPipelineName: "custom-pipeline", |
| 64 | + flagsSource: "", |
| 65 | + flagsDestination: "", |
| 66 | + expected: "custom-pipeline", |
| 67 | + }, |
| 68 | + { |
| 69 | + name: "Default pipeline name with custom source and destination", |
| 70 | + argsPipelineName: defaultPipelineName, |
| 71 | + flagsSource: "custom-source", |
| 72 | + flagsDestination: "custom-destination", |
| 73 | + expected: "custom-source-to-custom-destination", |
| 74 | + }, |
| 75 | + { |
| 76 | + name: "Default pipeline name with custom source only", |
| 77 | + argsPipelineName: defaultPipelineName, |
| 78 | + flagsSource: "custom-source", |
| 79 | + flagsDestination: "", |
| 80 | + expected: fmt.Sprintf("custom-source-to-%s", defaultDestination), |
| 81 | + }, |
| 82 | + { |
| 83 | + name: "Default pipeline name with custom destination only", |
| 84 | + argsPipelineName: defaultPipelineName, |
| 85 | + flagsSource: "", |
| 86 | + flagsDestination: "custom-destination", |
| 87 | + expected: fmt.Sprintf("%s-to-custom-destination", defaultSource), |
| 88 | + }, |
| 89 | + { |
| 90 | + name: "Default pipeline name with default source and destination", |
| 91 | + argsPipelineName: defaultPipelineName, |
| 92 | + flagsSource: "", |
| 93 | + flagsDestination: "", |
| 94 | + expected: fmt.Sprintf("%s-to-%s", defaultSource, defaultDestination), |
| 95 | + }, |
| 96 | + } |
| 97 | + |
| 98 | + for _, tt := range tests { |
| 99 | + t.Run(tt.name, func(t *testing.T) { |
| 100 | + is := is.New(t) |
| 101 | + c := &InitCommand{} |
| 102 | + |
| 103 | + c.args.pipelineName = tt.argsPipelineName |
| 104 | + c.flags.Source = tt.flagsSource |
| 105 | + c.flags.Destination = tt.flagsDestination |
| 106 | + |
| 107 | + got := c.getPipelineName() |
| 108 | + is.Equal(got, tt.expected) |
| 109 | + }) |
| 110 | + } |
| 111 | +} |
0 commit comments