|
| 1 | +package flags |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/loft-sh/devspace/cmd/flags" |
| 8 | + "github.com/loft-sh/devspace/pkg/devspace/env" |
| 9 | + "github.com/spf13/cobra" |
| 10 | + "gotest.tools/assert" |
| 11 | +) |
| 12 | + |
| 13 | +func Test_ApplyExtraFlagsWithEmpty(t *testing.T) { |
| 14 | + mycmd := cobra.Command{} |
| 15 | + flags, err := ApplyExtraFlags(&mycmd, []string{}, false) |
| 16 | + assert.NilError(t, err, "Error applying extra flags") |
| 17 | + assert.Equal(t, 0, len(flags), "Flags should be empty") |
| 18 | +} |
| 19 | + |
| 20 | +func Test_ApplyExtraFlagsWithDevspaceFlags(t *testing.T) { |
| 21 | + devspaceFlags := env.GlobalGetEnv("DEVSPACE_FLAGS") |
| 22 | + assert.Equal(t, "", devspaceFlags, "DEVSPACE_FLAGS should be empty") |
| 23 | + |
| 24 | + devspaceFlags = "-s --kubeconfig /path/to/kubeconfig --debug" |
| 25 | + err := os.Setenv("DEVSPACE_FLAGS", devspaceFlags) |
| 26 | + assert.NilError(t, err, "Error setting DEVSPACE_FLAGS") |
| 27 | + mycmd := &cobra.Command{} |
| 28 | + persistentFlags := mycmd.PersistentFlags() |
| 29 | + _ = flags.SetGlobalFlags(persistentFlags) |
| 30 | + |
| 31 | + flags, err := ApplyExtraFlags(mycmd, []string{}, false) |
| 32 | + assert.NilError(t, err, "Error applying extra flags") |
| 33 | + assert.Equal(t, 4, len(flags), "Flags should have 4 elements") |
| 34 | + |
| 35 | + kubeconfig := env.GlobalGetEnv("KUBECONFIG") |
| 36 | + assert.Equal(t, "/path/to/kubeconfig", kubeconfig, "Path should be /path/to/kubeconfig") |
| 37 | +} |
0 commit comments