-
Notifications
You must be signed in to change notification settings - Fork 3
/
list_test.go
109 lines (96 loc) · 2.07 KB
/
list_test.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2017 Josh Komoroske. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE.txt file.
package ykman
import (
"errors"
"fmt"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
)
func TestListParse(t *testing.T) {
var errorGeneric = errors.New("generic error")
tests := []struct {
title string
body string
error error
expectedNames []string
expectedError error
}{
{
title: "empty results",
expectedNames: []string{},
},
{
title: "single result",
body: `
aws
`,
expectedNames: []string{"aws"},
},
{
title: "single result with spaces",
body: `
aws main account
`,
expectedNames: []string{"aws main account"},
},
{
title: "multiple results",
body: `
aws
aws-cn
aws-us-gov
`,
expectedNames: []string{"aws", "aws-cn", "aws-us-gov"},
},
{
title: "multiple results with spaces",
body: `
aws
aws-cn
aws main account
`,
expectedNames: []string{"aws", "aws-cn", "aws main account"},
},
{
title: "ykman executable missing",
error: &exec.Error{
Err: exec.ErrNotFound,
},
expectedError: ErrorYkmanNotFound,
},
{
title: "no yubikey detected",
body: `
Usage: ykman [OPTIONS] COMMAND [ARGS]...
Error: No YubiKey detected!
`,
error: errorGeneric,
expectedError: ErrorYubikeyNotDetected,
},
{
title: "no yubikey detected",
body: `
Usage: ykman [OPTIONS] COMMAND [ARGS]...
Error: Failed connecting to the YubiKey.
`,
error: errorGeneric,
expectedError: ErrorYubikeyNotDetected,
},
{
title: "generic error",
error: errorGeneric,
expectedError: errorGeneric,
},
}
for index, test := range tests {
name := fmt.Sprintf("case #%d - %s", index, test.title)
t.Run(name, func(t *testing.T) {
actualNames, actualError := parseList(test.body, test.error)
assert.Equal(t, test.expectedError, actualError)
assert.Equal(t, test.expectedNames, actualNames)
})
}
}