-
Notifications
You must be signed in to change notification settings - Fork 84
/
resource_test.go
48 lines (45 loc) · 1.22 KB
/
resource_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
package kubernetes
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseResourceLocation(t *testing.T) {
for _, test := range []struct {
name string
s string
expected *ResourceLocation
expectedError string
}{
{
name: "empty string",
expectedError: `invalid resource location, expected format "namespace/name" but got ""`,
},
{
name: "missing namespace",
s: "/foo-name",
expectedError: `invalid resource location, expected format "namespace/name" but got "/foo-name"`,
},
{
name: "missing name",
s: "foo-ns/",
expectedError: `invalid resource location, expected format "namespace/name" but got "foo-ns/"`,
},
{
name: "valid resource location",
s: "foo-ns/foo-name",
expected: &ResourceLocation{Namespace: "foo-ns", Name: "foo-name"},
},
} {
t.Run(test.name, func(t *testing.T) {
result, err := ParseResourceLocation(test.s)
if test.expectedError != "" {
require.Error(t, err)
assert.Equal(t, test.expectedError, err.Error())
} else {
require.NoError(t, err)
assert.Equal(t, test.expected, result)
}
})
}
}