-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain_test.go
58 lines (47 loc) · 1.06 KB
/
chain_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
package main
import (
"io/ioutil"
"path/filepath"
"testing"
"time"
"github.com/andreyvit/diff"
"github.com/fatih/color"
)
func TestChainString(t *testing.T) {
testCases := []struct {
filename string
t time.Time
}{
{
"google.crt", time.Date(2014, 03, 15, 15, 10, 0, 0, time.UTC),
},
}
// Set timezone to fixate serialization of datetime
loc, err := time.LoadLocation("UTC")
if err != nil {
t.Fatal(err)
}
time.Local = loc
for _, c := range testCases {
filename := filepath.Join("testdata", c.filename)
golden := filepath.Join("testdata", c.filename+".golden")
certs, err := load(filename)
if err != nil {
t.Fatal(err)
}
// enforce color output
color.NoColor = false
got := NewChain(certs, c.t, false).String()
if *update {
ioutil.WriteFile(golden, []byte(got), 0644)
}
wantBytes, err := ioutil.ReadFile(golden)
if err != nil {
t.Fatal(err)
}
want := string(wantBytes)
if got != want {
t.Errorf("%s serialization doesn't match golden file %s:\n%v", filename, golden, diff.LineDiff(want, got))
}
}
}