github.com/argoproj/argo-cd/v3@v3.2.1/cmd/argocd/commands/logout_test.go (about) 1 package commands 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 10 argocdclient "github.com/argoproj/argo-cd/v3/pkg/apiclient" 11 "github.com/argoproj/argo-cd/v3/util/localconfig" 12 ) 13 14 func TestLogout(t *testing.T) { 15 // Write the test config file 16 err := os.WriteFile(testConfigFilePath, []byte(testConfig), os.ModePerm) 17 require.NoError(t, err) 18 defer os.Remove(testConfigFilePath) 19 20 err = os.Chmod(testConfigFilePath, 0o600) 21 require.NoError(t, err) 22 23 localConfig, err := localconfig.ReadLocalConfig(testConfigFilePath) 24 require.NoError(t, err) 25 assert.Equal(t, "localhost:8080", localConfig.CurrentContext) 26 assert.Contains(t, localConfig.Contexts, localconfig.ContextRef{Name: "localhost:8080", Server: "localhost:8080", User: "localhost:8080"}) 27 28 command := NewLogoutCommand(&argocdclient.ClientOptions{ConfigPath: testConfigFilePath}) 29 command.Run(nil, []string{"localhost:8080"}) 30 31 localConfig, err = localconfig.ReadLocalConfig(testConfigFilePath) 32 require.NoError(t, err) 33 assert.Equal(t, "localhost:8080", localConfig.CurrentContext) 34 assert.NotContains(t, localConfig.Users, localconfig.User{AuthToken: "vErrYS3c3tReFRe$hToken", Name: "localhost:8080"}) 35 assert.Contains(t, localConfig.Contexts, localconfig.ContextRef{Name: "argocd1.example.com:443", Server: "argocd1.example.com:443", User: "argocd1.example.com:443"}) 36 assert.Contains(t, localConfig.Contexts, localconfig.ContextRef{Name: "argocd2.example.com:443", Server: "argocd2.example.com:443", User: "argocd2.example.com:443"}) 37 assert.Contains(t, localConfig.Contexts, localconfig.ContextRef{Name: "localhost:8080", Server: "localhost:8080", User: "localhost:8080"}) 38 }