-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgosumtrim_test.go
50 lines (42 loc) · 978 Bytes
/
gosumtrim_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
package main
import (
"bytes"
"io"
"io/ioutil"
"os"
"testing"
"github.com/google/go-cmp/cmp"
)
const (
root = "./" // module root
inModFile = root + "testdata/go.mod.in"
inSumFile = root + "testdata/go.sum.in"
outSumFile = root + "testdata/go.sum.out"
)
func TestTrim(t *testing.T) {
mod := mustOpen(t, inModFile)
sum := mustOpen(t, inSumFile)
out := mustOpen(t, outSumFile)
want, err := ioutil.ReadAll(out)
if err != nil {
t.Fatalf("ioutil.ReadAll(out) failed: %v", err)
}
b := bytes.NewBuffer(nil)
if err := trim(mod, sum, b); err != nil {
t.Fatalf("trime() failed: %v", err)
}
got := b.Bytes()
t.Logf("got:\n%v", string(got))
t.Logf("want:\n%v", string(want))
if diff := cmp.Diff(string(got), string(want)); diff != "" {
t.Fatalf("trime() returned:\n%s", diff)
}
}
func mustOpen(t *testing.T, fn string) io.Reader {
t.Helper()
r, err := os.Open(fn)
if err != nil {
t.Fatalf("os.Open(%q) failed: %v", fn, err)
}
return r
}