generated from axetroy/go-cli-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 10
/
7_whatchanged_test.go
90 lines (84 loc) · 2.14 KB
/
7_whatchanged_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package whatchanged
import (
"bytes"
"context"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGenerate(t *testing.T) {
type TestCase struct {
name string
options *Options
Project string
ResultFile string
wantErr error
}
var tests = []TestCase{
{
name: "vscode-deno",
Project: "./__test__/vscode-deno",
ResultFile: "./__test__/vscode-deno.CHANGELOG.md",
options: &Options{
Version: []string{"HEAD~"},
},
},
{
name: "v",
Project: "./__test__/v",
ResultFile: "./__test__/v.CHANGELOG.md",
options: &Options{
Version: []string{"HEAD~"},
},
},
{
name: "test-first-commit",
Project: "./__test__/test-first-commit",
ResultFile: "./__test__/test-first-commit.CHANGELOG.md",
options: &Options{
Version: []string{"HEAD~"},
Preset: PresetFull,
},
},
{
name: "whatchanged single version",
Project: "./",
ResultFile: "./__test__/whatchanged-[v0.2.0].CHANGELOG.md",
options: &Options{
Version: []string{"v0.2.0"},
},
},
{
name: "whatchanged version range",
Project: "./",
ResultFile: "./__test__/whatchanged-[v0.2.0~v0.1.0].CHANGELOG.md",
options: &Options{
Version: []string{"v0.2.0~v0.1.0"},
},
},
{
name: "whatchanged version range",
Project: "./",
ResultFile: "./__test__/whatchanged-[23448a5482359f28a0089b17280dd2a0a0eaef26~9dff4fc6a9d746ffd9dd10215cf04d2fec2edd2a].CHANGELOG.md",
options: &Options{
Version: []string{"23448a5482359f28a0089b17280dd2a0a0eaef26~9dff4fc6a9d746ffd9dd10215cf04d2fec2edd2a"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := &bytes.Buffer{}
if err := Generate(context.Background(), tt.Project, w, tt.options); err != tt.wantErr {
t.Errorf("Generate() error = %v, wantErr %v", err, tt.wantErr)
return
}
if b, err := ioutil.ReadFile(tt.ResultFile); err != nil {
t.Errorf("Generate() error = %v, wantErr %v", err, tt.wantErr)
} else {
if gotW := w.String(); gotW != string(b) {
assert.Equal(t, w.String(), string(b), tt.name)
}
}
})
}
}