forked from veraison/swid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globalattributes_test.go
59 lines (49 loc) · 1.18 KB
/
globalattributes_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
// Copyright 2020 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package swid
import (
"encoding/xml"
"testing"
cbor "github.com/fxamacker/cbor/v2"
"github.com/stretchr/testify/assert"
)
func TestGlobalAttributes_MixingExtensionsEncode(t *testing.T) {
type DummyExtension struct {
FooFoo string `cbor:"32768,keyasint" xml:"http://localhost/tns foofoo,attr"`
}
type X struct {
GlobalAttributes
DummyExtension
}
x := X{
GlobalAttributes{
Lang: "babel",
},
DummyExtension{
FooFoo: "bing",
},
}
expected := `<X xml:lang="babel" xmlns:tns="http://localhost/tns" tns:foofoo="bing"></X>`
data, err := xml.Marshal(x)
assert.Nil(t, err)
assert.Equal(t, expected, string(data))
data, err = cbor.Marshal(x)
assert.Nil(t, err)
t.Logf("%x", data)
assert.Equal(t,
[]byte{
/*
a2 # map(2)
0f # unsigned(15)
65 # text(5)
626162656c # "babel"
19 8000 # unsigned(32768)
64 # text(4)
62696e67 # "bing"
*/
0xa2, 0x0f, 0x65, 0x62, 0x61, 0x62, 0x65, 0x6c, 0x19, 0x80, 0x00,
0x64, 0x62, 0x69, 0x6e, 0x67,
},
data,
)
}