aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/cli/cmd/api_key_test.go
blob: 18baec91e0c3eb18fc83b1fdd5a3257486c87f06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright Vespa.ai. 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: Developer 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")
}