-
Notifications
You must be signed in to change notification settings - Fork 9
/
types_test.go
53 lines (39 loc) · 1.02 KB
/
types_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
package ssi
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseURI(t *testing.T) {
t.Run("for VC types", func(t *testing.T) {
u, err := ParseURI("SomeType")
if !assert.NoError(t, err) {
return
}
assert.Equal(t, "SomeType", u.String())
})
t.Run("for URI types", func(t *testing.T) {
u, err := ParseURI("https://example.com/context/v1")
if !assert.NoError(t, err) {
return
}
assert.Equal(t, "https://example.com/context/v1", u.String())
})
t.Run("malformed input", func(t *testing.T) {
_, err := ParseURI(string([]byte{0}))
assert.Error(t, err)
})
}
func TestMustParseURI(t *testing.T) {
assert.Panics(t, func() {
MustParseURI(string([]byte{0}))
})
}
func TestURI_String(t *testing.T) {
assert.Equal(t, "http://test", URI{url.URL{Scheme: "http", Host: "test"}}.String())
}
func TestURI_MarshalText(t *testing.T) {
actual, err := URI{url.URL{Scheme: "http", Host: "test"}}.MarshalText()
assert.NoError(t, err)
assert.Equal(t, []byte("http://test"), actual)
}