-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathalias_test.go
More file actions
68 lines (62 loc) · 1.51 KB
/
alias_test.go
File metadata and controls
68 lines (62 loc) · 1.51 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
package claircore
import (
"fmt"
"testing"
"unique"
)
func alias(space, name string) Alias {
return Alias{
Space: unique.Make(space),
Name: name,
}
}
func ExampleAlias_uri() {
fmt.Println(alias("https://example.com/", "CVE-2014-0160"))
// Output:
// https://example.com/#CVE-2014-0160
}
func ExampleAlias_cve() {
fmt.Println(alias("CVE", "2014-0160"))
// Output:
// CVE-2014-0160
}
func ExampleAlias_Equal() {
a, b := alias("CVE", "2014-0160"), alias("CVE", "2014-0160")
fmt.Println("equal:", a.Equal(b))
// Output:
// equal: true
}
func TestAlias(t *testing.T) {
t.Run("Valid", func(t *testing.T) {
t.Run("OK", func(t *testing.T) {
a := Alias{Space: unique.Make("TEST"), Name: "1"}
if got, want := a.Valid(), true; got != want {
t.Errorf("got: %v, want: %v", got, want)
}
})
t.Run("Zero", func(t *testing.T) {
a := Alias{}
if got, want := a.Valid(), false; got != want {
t.Errorf("got: %v, want: %v", got, want)
}
})
t.Run("MissingSpace", func(t *testing.T) {
a := Alias{Name: "1"}
if got, want := a.Valid(), false; got != want {
t.Errorf("got: %v, want: %v", got, want)
}
})
t.Run("EmptySpace", func(t *testing.T) {
a := Alias{Space: unique.Make(""), Name: "1"}
if got, want := a.Valid(), false; got != want {
t.Errorf("got: %v, want: %v", got, want)
}
})
t.Run("MissingName", func(t *testing.T) {
a := Alias{Space: unique.Make("TEST")}
if got, want := a.Valid(), false; got != want {
t.Errorf("got: %v, want: %v", got, want)
}
})
})
}