-
Notifications
You must be signed in to change notification settings - Fork 21
/
checks_test.go
106 lines (96 loc) · 2.76 KB
/
checks_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
// SPDX-FileCopyrightText: 2017 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseDeviceAccessCheck(t *testing.T) {
testCases := []struct {
config deviceAccessCheck
name string
fails bool
expectedCheckName string
expectedWRPCredPath string
expectedDeviceCredPath string
expectedErr error
}{
{
name: "Missing Required name",
config: deviceAccessCheck{
DeviceCredentialPath: "dcp",
WRPCredentialPath: "wcp",
Op: IntersectsOp,
},
expectedErr: errNameRequired,
fails: true,
},
{
name: "Missing DeviceCredentialPath",
config: deviceAccessCheck{
Name: "invalid check",
WRPCredentialPath: "wrpPath",
Op: IntersectsOp,
},
expectedErr: errDeviceCredPathRequired,
fails: true,
},
{
name: "Nothing to compare device credential to",
config: deviceAccessCheck{
Name: "nonEmpty",
DeviceCredentialPath: "dcp",
Op: IntersectsOp,
},
expectedErr: errInputValueOrWRPCredPathRequired,
fails: true,
},
{
name: "Bad operator",
config: deviceAccessCheck{
Name: "nonEmpty",
DeviceCredentialPath: "dcp",
InputValue: 3,
Op: "bad",
},
expectedErr: errOpNotSupported,
fails: true,
},
{
name: "Happpy path",
config: deviceAccessCheck{
Name: " trimWhiteSpaces ",
DeviceCredentialPath: " dcp",
WRPCredentialPath: "wcp ",
InputValue: []string{"e0", "e1"},
Op: IntersectsOp,
Inversed: true,
},
expectedCheckName: "trimWhiteSpaces",
expectedDeviceCredPath: "dcp",
expectedWRPCredPath: "wcp",
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
parsedCheck, err := parseDeviceAccessCheck(testCase.config)
if testCase.fails {
require.NotNil(err)
require.Nil(parsedCheck)
assert.Equal(testCase.expectedErr, err)
} else {
require.Nil(err)
require.NotNil(parsedCheck)
require.NotNil(parsedCheck.assertion)
assert.Equal(testCase.expectedCheckName, parsedCheck.name)
assert.Equal(testCase.expectedDeviceCredPath, parsedCheck.deviceCredentialPath)
assert.Equal(testCase.expectedWRPCredPath, parsedCheck.wrpCredentialPath)
assert.Equal(testCase.config.Inversed, parsedCheck.inversed)
assert.Equal(testCase.config.InputValue, parsedCheck.inputValue)
}
})
}
}