-
Notifications
You must be signed in to change notification settings - Fork 4
/
capabilities_test.go
97 lines (79 loc) · 2.39 KB
/
capabilities_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
// SPDX-FileCopyrightText: 2024 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package bascule
import (
"testing"
"github.com/stretchr/testify/suite"
)
type CapabilitiesTestSuite struct {
suite.Suite
}
func (suite *CapabilitiesTestSuite) testGetCapabilitiesNil() {
caps, ok := GetCapabilities(nil)
suite.False(ok)
suite.Empty(caps)
}
func (suite *CapabilitiesTestSuite) testGetCapabilitiesAccessor() {
suite.Run("NoCapabilities", func() {
mt := new(mockToken)
caps, ok := GetCapabilities(mt)
suite.False(ok)
suite.Empty(caps)
mt.AssertExpectations(suite.T())
})
suite.Run("EmptyCapabilities", func() {
mt := new(mockTokenWithCapabilities)
mt.ExpectCapabilities().Once()
caps, ok := GetCapabilities(mt)
suite.True(ok)
suite.Empty(caps)
mt.AssertExpectations(suite.T())
})
suite.Run("HasCapabilities", func() {
mt := new(mockTokenWithCapabilities)
mt.ExpectCapabilities("one", "two", "three").Once()
caps, ok := GetCapabilities(mt)
suite.True(ok)
suite.Equal([]string{"one", "two", "three"}, caps)
mt.AssertExpectations(suite.T())
})
}
func (suite *CapabilitiesTestSuite) testGetCapabilitiesStringSlice() {
suite.Run("Empty", func() {
caps, ok := GetCapabilities([]string{})
suite.True(ok)
suite.Empty(caps)
})
suite.Run("NonEmpty", func() {
caps, ok := GetCapabilities([]string{"one", "two", "three"})
suite.True(ok)
suite.Equal([]string{"one", "two", "three"}, caps)
})
}
func (suite *CapabilitiesTestSuite) testGetCapabilitiesString() {
caps, ok := GetCapabilities("single")
suite.True(ok)
suite.Equal([]string{"single"}, caps)
}
func (suite *CapabilitiesTestSuite) testGetCapabilitiesAnySlice() {
suite.Run("AllStrings", func() {
caps, ok := GetCapabilities([]any{"one", "two", "three"})
suite.True(ok)
suite.Equal([]string{"one", "two", "three"}, caps)
})
suite.Run("NonStrings", func() {
caps, ok := GetCapabilities([]any{"one", 2.0, 3})
suite.False(ok)
suite.Empty(caps)
})
}
func (suite *CapabilitiesTestSuite) TestGetCapabilities() {
suite.Run("Nil", suite.testGetCapabilitiesNil)
suite.Run("Accessor", suite.testGetCapabilitiesAccessor)
suite.Run("StringSlice", suite.testGetCapabilitiesStringSlice)
suite.Run("String", suite.testGetCapabilitiesString)
suite.Run("AnySlice", suite.testGetCapabilitiesAnySlice)
}
func TestCapabilities(t *testing.T) {
suite.Run(t, new(CapabilitiesTestSuite))
}