-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathmain_test.go
73 lines (60 loc) · 1.56 KB
/
main_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
package main
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_buildConfig(t *testing.T) {
testCases := []struct {
desc string
inputPath string
minVersion version
expected string
}{
{
desc: "v1",
inputPath: "all-releases.json",
minVersion: version{major: 1, minor: 28, patch: 3},
expected: "github-action-config.json",
},
{
desc: "v1 only",
inputPath: "all-releases-v2.json",
minVersion: version{major: 1, minor: 28, patch: 3},
expected: "github-action-config-v1.json",
},
{
desc: "v2",
inputPath: "all-releases-v2.json",
minVersion: version{major: 2, minor: 0, patch: 0},
expected: "github-action-config-v2.json",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
allReleases := unmarshalRelease(t, test.inputPath)
config, err := buildConfig(allReleases, test.minVersion)
require.NoError(t, err)
data, err := json.MarshalIndent(config, "", " ")
require.NoError(t, err)
expected, err := os.ReadFile(filepath.Join("testdata", test.expected))
require.NoError(t, err)
assert.JSONEq(t, string(expected), string(data))
})
}
}
func unmarshalRelease(t *testing.T, filename string) []release {
file, err := os.Open(filepath.Join("testdata", filename))
require.NoError(t, err)
t.Cleanup(func() {
_ = file.Close()
})
var data []release
err = json.NewDecoder(file).Decode(&data)
require.NoError(t, err)
return data
}