mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
Every command is cd-*: cd, cd-server, cd-repo-server, cd-application-controller, cd-applicationset-controller, cd-cmp-server, cd-commit-server, cd-dex, cd-git-ask-pass, cd-k8s-auth, cd-notification. util/argo is util/cd; util/notification/argocd is util/notification/cd. Preserved deliberately: github.com/argoproj/argocd-example-apps is an EXTERNAL repo used as an e2e fixture, and notifications-engine + pkg/v2 are real dependencies. Renaming a URL we do not own would break the tests. Two bugs I made and caught, both from a careless sed: - s/argo/cd/g turned 'argocd' into 'cdcd' in two directory names - renaming the package declaration left every call site saying argo.X go build ./... exit 0. Co-authored-by: Hanzo Dev <[email protected]>
106 lines
2.2 KiB
Go
106 lines
2.2 KiB
Go
package initialize
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
flag "github.com/spf13/pflag"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type StringFlag struct {
|
|
// The exact value provided on the flag
|
|
value string
|
|
}
|
|
|
|
func (f StringFlag) String() string {
|
|
return f.value
|
|
}
|
|
|
|
func (f *StringFlag) Set(value string) error {
|
|
f.value = value
|
|
return nil
|
|
}
|
|
|
|
func (f *StringFlag) Type() string {
|
|
return "string"
|
|
}
|
|
|
|
func Test_FlagContextNotChanged(t *testing.T) {
|
|
res := RetrieveContextIfChanged(&flag.Flag{
|
|
Name: "",
|
|
Shorthand: "",
|
|
Usage: "",
|
|
Value: &StringFlag{value: "test"},
|
|
DefValue: "",
|
|
Changed: false,
|
|
NoOptDefVal: "",
|
|
Deprecated: "",
|
|
Hidden: false,
|
|
ShorthandDeprecated: "",
|
|
Annotations: nil,
|
|
})
|
|
|
|
assert.Empty(t, res)
|
|
}
|
|
|
|
func Test_FlagContextChanged(t *testing.T) {
|
|
res := RetrieveContextIfChanged(&flag.Flag{
|
|
Name: "",
|
|
Shorthand: "",
|
|
Usage: "",
|
|
Value: &StringFlag{value: "test"},
|
|
DefValue: "",
|
|
Changed: true,
|
|
NoOptDefVal: "",
|
|
Deprecated: "",
|
|
Hidden: false,
|
|
ShorthandDeprecated: "",
|
|
Annotations: nil,
|
|
})
|
|
|
|
assert.Equal(t, "test", res)
|
|
}
|
|
|
|
func Test_FlagContextNil(t *testing.T) {
|
|
res := RetrieveContextIfChanged(&flag.Flag{
|
|
Name: "",
|
|
Shorthand: "",
|
|
Usage: "",
|
|
Value: nil,
|
|
DefValue: "",
|
|
Changed: false,
|
|
NoOptDefVal: "",
|
|
Deprecated: "",
|
|
Hidden: false,
|
|
ShorthandDeprecated: "",
|
|
Annotations: nil,
|
|
})
|
|
|
|
assert.Empty(t, res)
|
|
}
|
|
|
|
func Test_InitCommand_FiltersUnsupportedKubectlFlags(t *testing.T) {
|
|
cmd := &cobra.Command{}
|
|
|
|
InitCommand(cmd)
|
|
|
|
unsupported := []string{
|
|
"disable-compression",
|
|
"certificate-authority",
|
|
"client-certificate",
|
|
"client-key",
|
|
"as",
|
|
"as-group",
|
|
"as-uid",
|
|
"tls-server-name",
|
|
}
|
|
|
|
for _, f := range unsupported {
|
|
assert.Nil(t, cmd.Flags().Lookup(f))
|
|
}
|
|
|
|
assert.NotNil(t, cmd.Flags().Lookup("context"))
|
|
assert.NotNil(t, cmd.Flags().Lookup("namespace"))
|
|
}
|