summaryrefslogtreecommitdiffstats
path: root/client/go/cmd/api_key_test.go
blob: 2497568604f8228567496c2c339d57d42c2af831 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: mpolden

package cmd

import (
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestAPIKey(t *testing.T) {
	homeDir := t.TempDir()
	keyFile := homeDir + "/.vespa/t1.api-key.pem"

	out, _ := execute(command{args: []string{"api-key", "-a", "t1.a1.i1"}, homeDir: homeDir}, t, nil)
	assert.True(t, strings.HasPrefix(out, "Success: API private key written to "+keyFile+"\n"))

	out, _ = execute(command{args: []string{"api-key", "-a", "t1.a1.i1"}, homeDir: homeDir}, t, nil)
	assert.True(t, strings.HasPrefix(out, "Error: File "+keyFile+" already exists\nHint: Use -f to overwrite it\n"))
	assert.True(t, strings.Contains(out, "This is your public key"))
}