-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
49 lines (42 loc) · 1.1 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
package main
import (
"os"
"testing"
"github.com/h2non/gock"
"github.com/nbio/st"
"github.com/shotah/forgecli/forgecli"
)
func MockCurseForgeVersions(t *testing.T) {
mockVersionTypes := "./forgecli/mocks/mc_version_types.json"
body, err := os.ReadFile(mockVersionTypes)
st.Expect(t, err, nil)
gock.New("https://api.curseforge.com").
Get("/v1/games/432/version-types").
Reply(200).
JSON(body)
}
func MockCurseForgeModResponse(t *testing.T) {
mockVersionTypes := "./forgecli/mocks/voice_mod_response.json"
body, err := os.ReadFile(mockVersionTypes)
st.Expect(t, err, nil)
gock.New("https://api.curseforge.com").
Get("/v1/mods/416089/files?gameVersionTypeID=73250&index=0&pageSize=999").
Reply(200).
JSON(body)
}
func TestHelp(t *testing.T) {
defer gock.Off()
MockCurseForgeVersions(t)
MockCurseForgeModResponse(t)
expected := 2
os.Args = []string{"-help"}
actual := forgecli.CLI(os.Args[1:])
if actual != expected {
t.Errorf("Test failed, expected: '%d', got: '%d'", expected, actual)
}
}
func TestMain(m *testing.M) {
os.Args = []string{"-help"}
exitVal := m.Run()
os.Exit(exitVal)
}