mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
* Add `Prompt`, with `prompts.enabled` setting in `argocd-cm` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Make `SettingsOpts`, `SettingsOpts.ArgocdCMPath`, `SettingsOpts.CreateSettingsManager()` and `commandContext.CreateSettingsManager()` exportable Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add `prompt_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Refactor `NewPrompt()` and move into new package `utils` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Update `NewPrompt()` to use local config Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add `NewConfigurationCommand()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Move `prompt_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Remove `prompt_test.go` for now Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add back and update `prompt_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add `configuration_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix linting issues Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix linting issues Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Reverse early-termination logic in `Confirm()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Rename `ArgocdCMPath` to `argocdCMPath` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Rename `SettingsOpts` to `settingsOpts` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Rename `CreateSettingsManager()` to `createSettingsManager()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Rename `configuration` to `configure` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Further rename `configuration` to `configure` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Remove redundant Argo CD ConfigMap logic Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix terminal output spacing Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Make `argocd configure` use local config value as the default value for `--prompts-enabled` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add global CLI flag `--force-prompts-enabled` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Update existing `prompt_test.go` test cases Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add test case for `(p *Prompt).Confirm()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add test cases for `GetBoolFlagWithFallback()` to `env_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Format imports Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Further format imports and remove unused variable Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Again format imports Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add fallback to `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix bug in `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix missing import Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add auto-generated docs for `argocd configure` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add auto-generated docs for new global CLI flag `--force-prompts-enabled` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Update `NewPrompt()` to receive a `bool` rather than `*apiclient.ClientOptions` arg Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Remove arg `fallback` from `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add arg `useCLIOpts bool` to `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Make `config.LoadFlags()` exportable Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add tests for `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix linting errors in tests Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Run `make codegen-local` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> --------- Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
151 lines
3.4 KiB
Go
151 lines
3.4 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func loadOpts(t *testing.T, opts string) {
|
|
t.Helper()
|
|
t.Setenv("ARGOCD_OPTS", opts)
|
|
assert.NoError(t, LoadFlags())
|
|
}
|
|
|
|
func loadInvalidOpts(t *testing.T, opts string) {
|
|
t.Helper()
|
|
t.Setenv("ARGOCD_OPTS", opts)
|
|
assert.Error(t, LoadFlags())
|
|
}
|
|
|
|
func TestNilOpts(t *testing.T) {
|
|
assert.Equal(t, "foo", GetFlag("foo", "foo"))
|
|
}
|
|
|
|
func TestEmptyOpts(t *testing.T) {
|
|
loadOpts(t, "")
|
|
|
|
assert.Equal(t, "foo", GetFlag("foo", "foo"))
|
|
}
|
|
|
|
func TestRubbishOpts(t *testing.T) {
|
|
loadInvalidOpts(t, "rubbish")
|
|
}
|
|
|
|
func TestBoolFlag(t *testing.T) {
|
|
loadOpts(t, "--foo")
|
|
|
|
assert.True(t, GetBoolFlag("foo"))
|
|
}
|
|
|
|
func TestBoolFlagAtStart(t *testing.T) {
|
|
loadOpts(t, "--foo --bar baz")
|
|
|
|
assert.True(t, GetBoolFlag("foo"))
|
|
}
|
|
|
|
func TestBoolFlagInMiddle(t *testing.T) {
|
|
loadOpts(t, "--bar baz --foo --qux")
|
|
|
|
assert.True(t, GetBoolFlag("foo"))
|
|
}
|
|
|
|
func TestBooleanFlagAtEnd(t *testing.T) {
|
|
loadOpts(t, "--bar baz --foo")
|
|
|
|
assert.True(t, GetBoolFlag("foo"))
|
|
}
|
|
|
|
func TestIntFlag(t *testing.T) {
|
|
loadOpts(t, "--foo 2")
|
|
|
|
assert.Equal(t, 2, GetIntFlag("foo", 0))
|
|
}
|
|
|
|
func TestIntFlagAtStart(t *testing.T) {
|
|
loadOpts(t, "--foo 2 --bar baz")
|
|
|
|
assert.Equal(t, 2, GetIntFlag("foo", 0))
|
|
}
|
|
|
|
func TestIntFlagInMiddle(t *testing.T) {
|
|
loadOpts(t, "--bar baz --foo 2 --qux")
|
|
|
|
assert.Equal(t, 2, GetIntFlag("foo", 0))
|
|
}
|
|
|
|
func TestIntFlagAtEnd(t *testing.T) {
|
|
loadOpts(t, "--bar baz --foo 2")
|
|
|
|
assert.Equal(t, 2, GetIntFlag("foo", 0))
|
|
}
|
|
|
|
func TestStringSliceFlag(t *testing.T) {
|
|
loadOpts(t, "--header='Content-Type: application/json; charset=utf-8,Strict-Transport-Security: max-age=31536000'")
|
|
strings := GetStringSliceFlag("header", []string{})
|
|
|
|
assert.Len(t, strings, 2)
|
|
assert.Equal(t, "Content-Type: application/json; charset=utf-8", strings[0])
|
|
assert.Equal(t, "Strict-Transport-Security: max-age=31536000", strings[1])
|
|
}
|
|
|
|
func TestStringSliceFlagAtStart(t *testing.T) {
|
|
loadOpts(t, "--header='Strict-Transport-Security: max-age=31536000' --bar baz")
|
|
strings := GetStringSliceFlag("header", []string{})
|
|
|
|
assert.Len(t, strings, 1)
|
|
assert.Equal(t, "Strict-Transport-Security: max-age=31536000", strings[0])
|
|
}
|
|
|
|
func TestStringSliceFlagInMiddle(t *testing.T) {
|
|
loadOpts(t, "--bar baz --header='Strict-Transport-Security: max-age=31536000' --qux")
|
|
strings := GetStringSliceFlag("header", []string{})
|
|
|
|
assert.Len(t, strings, 1)
|
|
assert.Equal(t, "Strict-Transport-Security: max-age=31536000", strings[0])
|
|
}
|
|
|
|
func TestStringSliceFlagAtEnd(t *testing.T) {
|
|
loadOpts(t, "--bar baz --header='Strict-Transport-Security: max-age=31536000'")
|
|
strings := GetStringSliceFlag("header", []string{})
|
|
|
|
assert.Len(t, strings, 1)
|
|
assert.Equal(t, "Strict-Transport-Security: max-age=31536000", strings[0])
|
|
}
|
|
|
|
func TestFlagAtStart(t *testing.T) {
|
|
loadOpts(t, "--foo bar")
|
|
|
|
assert.Equal(t, "bar", GetFlag("foo", ""))
|
|
}
|
|
|
|
func TestFlagInTheMiddle(t *testing.T) {
|
|
loadOpts(t, "--baz --foo bar --qux")
|
|
|
|
assert.Equal(t, "bar", GetFlag("foo", ""))
|
|
}
|
|
|
|
func TestFlagAtTheEnd(t *testing.T) {
|
|
loadOpts(t, "--baz --foo bar")
|
|
|
|
assert.Equal(t, "bar", GetFlag("foo", ""))
|
|
}
|
|
|
|
func TestFlagWithSingleQuotes(t *testing.T) {
|
|
loadOpts(t, "--foo 'bar baz'")
|
|
|
|
assert.Equal(t, "bar baz", GetFlag("foo", ""))
|
|
}
|
|
|
|
func TestFlagWithDoubleQuotes(t *testing.T) {
|
|
loadOpts(t, "--foo \"bar baz\"")
|
|
|
|
assert.Equal(t, "bar baz", GetFlag("foo", ""))
|
|
}
|
|
|
|
func TestFlagWithEqualSign(t *testing.T) {
|
|
loadOpts(t, "--foo=bar")
|
|
|
|
assert.Equal(t, "bar", GetFlag("foo", ""))
|
|
}
|