Skip to content

Commit c108f5d

Browse files
author
Chris Gilmer
committed
Start tests for add-profile
1 parent c63a75c commit c108f5d

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

cmd/add_profile_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"testing"
7+
8+
"github.com/99designs/aws-vault/vault"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
var defaultConfigAddProfile = []byte(`[profile test-id-base]
13+
region=us-west-2
14+
output=json
15+
16+
[profile test-id]
17+
source_profile=test-id-base
18+
mfa_serial=arn:aws:iam::111111111111:mfa/test-user
19+
role_arn=arn:aws:iam::222222222222:role/engineer
20+
region=us-west-2
21+
output=json
22+
`)
23+
24+
func TestAddProfile(t *testing.T) {
25+
26+
// Test logger
27+
logger := log.New(os.Stdout, "", log.LstdFlags)
28+
logger.SetFlags(0)
29+
30+
f := newConfigFile(t, defaultConfigAddProfile)
31+
defer func() {
32+
errRemove := os.Remove(f)
33+
assert.NoError(t, errRemove)
34+
}()
35+
36+
config, err := vault.LoadConfig(f)
37+
assert.NoError(t, err)
38+
39+
addProfileConfig := AddProfileConfig{
40+
// Config
41+
Logger: logger,
42+
Config: config,
43+
44+
// Profile Inputs
45+
IAMRole: "test-role",
46+
Region: "us-west-2",
47+
Partition: "aws",
48+
Output: "json",
49+
50+
// Profiles
51+
AWSProfileAccounts: []string{"test-id:123456789012"},
52+
AWSProfileName: "test-id",
53+
}
54+
err = addProfileConfig.AddProfile()
55+
assert.NoError(t, err)
56+
57+
// TODO: Check contents of file
58+
}

cmd/setup_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ output=json
3636
assert.NoError(t, errRemove)
3737
}()
3838

39-
config, _ := vault.LoadConfig(f)
39+
config, err := vault.LoadConfig(f)
40+
assert.NoError(t, err)
41+
4042
keyring, err := getKeyring("test")
4143
assert.NoError(t, err)
44+
4245
setupConfig := SetupConfig{
4346
// Config
4447
Logger: logger,
@@ -59,6 +62,8 @@ output=json
5962
}
6063
err = setupConfig.UpdateAWSConfigFile()
6164
assert.NoError(t, err)
65+
66+
// TODO: Check contents of file
6267
}
6368

6469
func TestGenerateQrCode(t *testing.T) {

0 commit comments

Comments
 (0)