forked from veraison/corim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccaplatformconfigid_test.go
95 lines (85 loc) · 1.95 KB
/
ccaplatformconfigid_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
// Copyright 2021-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package comid
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCCAPlatformConfigID_Set_ok(t *testing.T) {
var cca CCAPlatformConfigID
err := cca.Set(TestCCALabel)
assert.NoError(t, err)
}
func TestCCAPlatformConfigID_Set_nok(t *testing.T) {
var cca CCAPlatformConfigID
expectedErr := "empty input string"
err := cca.Set("")
assert.EqualError(t, err, expectedErr)
}
func TestCCAPlatformConfigID_Get_nok(t *testing.T) {
var cca CCAPlatformConfigID
expectedErr := "empty CCA platform config ID"
_, err := cca.Get()
assert.EqualError(t, err, expectedErr)
}
func TestNewTaggedCCAPlatformConfigID(t *testing.T) {
testID := TaggedCCAPlatformConfigID("test")
untagged := CCAPlatformConfigID("test")
for _, tv := range []struct {
Name string
Input any
Err string
Expected TaggedCCAPlatformConfigID
}{
{
Name: "TaggedCCAPlatformConfigID ok",
Input: testID,
Expected: testID,
},
{
Name: "*TaggedCCAPlatformConfigID ok",
Input: &testID,
Expected: testID,
},
{
Name: "CCAPlatformConfigID ok",
Input: untagged,
Expected: testID,
},
{
Name: "*CCAPlatformConfigID ok",
Input: &untagged,
Expected: testID,
},
{
Name: "string ok",
Input: "test",
Expected: testID,
},
{
Name: "[]byte ok",
Input: []byte{0x74, 0x65, 0x73, 0x74},
Expected: testID,
},
{
Name: "[]byte not ok",
Input: []byte{0x80, 0x65, 0x73, 0x74},
Err: "bytes do not form a valid UTF-8 string",
},
{
Name: "bad type",
Input: 7,
Err: "unexpected type for CCA platform-config-id: int",
},
} {
t.Run(tv.Name, func(t *testing.T) {
out, err := NewTaggedCCAPlatformConfigID(tv.Input)
if tv.Err != "" {
assert.Nil(t, out)
assert.EqualError(t, err, tv.Err)
} else {
assert.Equal(t, tv.Expected, *out)
}
})
}
}