Repository navigation
Expand file tree
/
Copy pathcommon_test.go
More file actions
98 lines (91 loc) · 1.6 KB
/
Copy pathcommon_test.go
File metadata and controls
98 lines (91 loc) · 1.6 KB
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
// Copyright IBM Corp. 2022, 2025
// SPDX-License-Identifier: MPL-2.0
package nodeenrollment
import (
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"
)
func TestIsNil(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in any
want bool
}{
{
name: "nil outside",
in: nil,
want: true,
},
{
name: "nil interface type",
in: proto.Message(nil),
want: true,
},
{
name: "non pointer",
in: struct{}{},
want: false,
},
{
name: "pointer",
in: &struct{}{},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, IsNil(tt.in))
})
}
}
func TestContainsKnownAlpnProto(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in []string
want bool
}{
{
name: "nil",
in: nil,
want: false,
},
{
name: "single-no-proto",
in: []string{"foo"},
want: false,
},
{
name: "single-fetch-proto",
in: []string{FetchNodeCredsNextProtoV1Prefix},
want: true,
},
{
name: "single-auth-proto",
in: []string{AuthenticateNodeNextProtoV1Prefix},
want: true,
},
{
name: "multi-no-proto",
in: []string{"foo", "bar"},
want: false,
},
{
name: "multi-fetch-proto",
in: []string{"foo", FetchNodeCredsNextProtoV1Prefix},
want: true,
},
{
name: "multi-auth-proto",
in: []string{"foo", AuthenticateNodeNextProtoV1Prefix},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, ContainsKnownAlpnProto(tt.in...))
})
}
}