diff options
author | Martin Polden <mpolden@mpolden.no> | 2023-02-03 15:20:23 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2023-02-03 15:35:25 +0100 |
commit | e1e94812425a487069bf33f781bec987e9e49874 (patch) | |
tree | 4a892c3b5c0a7dee2cb76f9971e538cb4aba8a16 /client/go/internal/cli/cmd/api_key_test.go | |
parent | a08ae588d6035b69f0961dff596fc871fd1c4e58 (diff) |
Re-organize Go code
Diffstat (limited to 'client/go/internal/cli/cmd/api_key_test.go')
-rw-r--r-- | client/go/internal/cli/cmd/api_key_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/client/go/internal/cli/cmd/api_key_test.go b/client/go/internal/cli/cmd/api_key_test.go new file mode 100644 index 00000000000..9c14033f85b --- /dev/null +++ b/client/go/internal/cli/cmd/api_key_test.go @@ -0,0 +1,35 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Author: mpolden + +package cmd + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAPIKey(t *testing.T) { + t.Run("auth api-key", func(t *testing.T) { + testAPIKey(t, []string{"auth", "api-key"}) + }) +} + +func testAPIKey(t *testing.T, subcommand []string) { + cli, stdout, stderr := newTestCLI(t) + + err := cli.Run("config", "set", "target", "cloud") + assert.Nil(t, err) + + args := append(subcommand, "-a", "t1.a1.i1") + err = cli.Run(args...) + assert.Nil(t, err) + assert.Equal(t, "", stderr.String()) + assert.Contains(t, stdout.String(), "Success: API private key written to") + + err = cli.Run(subcommand...) + assert.NotNil(t, err) + assert.Contains(t, stderr.String(), "Error: refusing to overwrite") + assert.Contains(t, stderr.String(), "Hint: Use -f to overwrite it\n") + assert.Contains(t, stdout.String(), "This is your public key") +} |