-
Notifications
You must be signed in to change notification settings - Fork 34
/
install_test.go
114 lines (103 loc) · 2.94 KB
/
install_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package rook
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/Southclaws/sampctl/pkgcontext"
"github.com/Southclaws/sampctl/versioning"
)
func Test_PackageInstall(t *testing.T) {
type args struct {
targets []versioning.DependencyString
development bool
}
tests := []struct {
name string
pkg []byte
args args
wantErr bool
}{
{"simple", []byte(`{
"user": "Southclaws",
"repo": "install-test",
"entry": "gamemodes/test.pwn",
"output": "gamemodes/test.amx",
"dependencies": ["sampctl/samp-stdlib"]
}`), args{[]versioning.DependencyString{"thecodeah/pawn-humanize:v1.1.1"}, false}, false},
{"dev", []byte(`{
"user": "Southclaws",
"repo": "install-test",
"entry": "gamemodes/test.pwn",
"output": "gamemodes/test.amx",
"dependencies": ["sampctl/samp-stdlib"]
}`), args{[]versioning.DependencyString{"thecodeah/pawn-humanize:v1.1.1"}, true}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dir := filepath.Join("./tests/install", tt.name)
os.RemoveAll(dir)
os.MkdirAll(dir, 0700)
ioutil.WriteFile(filepath.Join(dir, "pawn.json"), tt.pkg, 0700) // nolint
pcx1, err := pkgcontext.NewPackageContext(gh, gitAuth, true, dir, runtime.GOOS, "./tests/cache", "", false)
if err != nil {
t.Error(err)
}
err = pcx1.Install(context.Background(), tt.args.targets, tt.args.development)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
pcx2, err := pkgcontext.NewPackageContext(gh, gitAuth, true, dir, runtime.GOOS, "./tests/cache", "", false)
if err != nil {
t.Error(err)
}
if tt.args.development {
for _, target := range tt.args.targets {
assert.Contains(t, pcx2.Package.Development, target)
}
} else {
for _, target := range tt.args.targets {
assert.Contains(t, pcx2.Package.Dependencies, target)
}
}
})
}
}
func Test_PackageGet(t *testing.T) {
type args struct {
dep versioning.DependencyMeta
dir string
}
tests := []struct {
name string
args args
wantErr bool
}{
{"direct", args{versioning.DependencyMeta{Site: "github.com", User: "thecodeah", Repo: "pawn-humanize", Tag: "v1.1.1"}, "./tests/get/direct"}, false},
{"get-auto", args{versioning.DependencyMeta{Site: "github.com", User: "thecodeah", Repo: "pawn-humanize", Tag: "v1.1.1"}, "./tests/get"}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.args.dir == "./tests/get" {
if os.RemoveAll(filepath.Join(tt.args.dir, tt.args.dep.Repo)) != nil {
panic("failed to remove get test dir")
}
} else {
if os.RemoveAll(tt.args.dir) != nil {
panic("failed to remove get test dir")
}
}
err := Get(context.Background(), gh, tt.args.dep, tt.args.dir, nil, runtime.GOOS, "./tests/cache")
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}