/
chocolatey_test.go
173 lines (153 loc) · 3.97 KB
/
chocolatey_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package chocolatey
import (
"os"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/golden"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/require"
)
func TestDescription(t *testing.T) {
require.NotEmpty(t, Pipe{}.String())
}
func TestSkip(t *testing.T) {
ctx := context.New(config.Project{})
require.True(t, Pipe{}.Skip(ctx))
}
func TestDefault(t *testing.T) {
testlib.Mktmp(t)
ctx := &context.Context{
TokenType: context.TokenTypeGitHub,
Config: config.Project{
ProjectName: "myproject",
Chocolateys: []config.Chocolatey{
{},
},
},
}
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, ctx.Config.ProjectName, ctx.Config.Chocolateys[0].Name)
require.Equal(t, ctx.Config.ProjectName, ctx.Config.Chocolateys[0].Title)
require.Equal(t, "v1", ctx.Config.Chocolateys[0].Goamd64)
}
func Test_doRun(t *testing.T) {
folder := t.TempDir()
file := filepath.Join(folder, "archive")
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
tests := []struct {
name string
choco config.Chocolatey
artifacts []artifact.Artifact
err string
}{
{
name: "no artifacts",
choco: config.Chocolatey{
Name: "app",
IDs: []string{"no-app"},
Goamd64: "v1",
},
err: "chocolatey requires a windows build and archive",
},
{
name: "success",
choco: config.Chocolatey{
Name: "app",
Goamd64: "v1",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Dist: folder,
ProjectName: "run-all",
},
}
ctx.Artifacts.Add(&artifact.Artifact{
Name: "app_1.0.1_windows_amd64.zip",
Path: file,
Goos: "windows",
Goarch: "amd64",
Goamd64: "v1",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
artifact.ExtraID: "app",
artifact.ExtraFormat: "zip",
},
})
client := client.NewMock()
got := doRun(ctx, client, tt.choco)
var err string
if got != nil {
err = got.Error()
}
if tt.err != err {
t.Errorf("Unexpected error: %s (expected %s)", err, tt.err)
}
})
}
}
func Test_buildNuspec(t *testing.T) {
ctx := &context.Context{
Version: "1.12.3",
}
choco := config.Chocolatey{
Name: "goreleaser",
IDs: []string{},
Title: "GoReleaser",
Authors: "caarlos0",
ProjectURL: "https://goreleaser.com/",
Tags: "go docker homebrew golang package",
Summary: "Deliver Go binaries as fast and easily as possible",
Description: "GoReleaser builds Go binaries for several platforms, creates a GitHub release and then pushes a Homebrew formula to a tap repository. All that wrapped in your favorite CI.",
Dependencies: []config.ChocolateyDependency{
{ID: "nfpm"},
},
}
out, err := buildNuspec(ctx, choco)
require.NoError(t, err)
golden.RequireEqualExt(t, out, ".nuspec")
}
func Test_buildScript(t *testing.T) {
folder := t.TempDir()
file := filepath.Join(folder, "archive")
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
ctx := &context.Context{
Version: "1.0.0",
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
}
choco := config.Chocolatey{}
client := client.NewMock()
artifacts := []*artifact.Artifact{
{
Name: "app_1.0.0_windows_386.zip",
Goos: "windows",
Goarch: "386",
Goamd64: "v1",
Path: file,
},
{
Name: "app_1.0.0_windows_amd64.zip",
Goos: "windows",
Goarch: "amd64",
Goamd64: "v1",
Path: file,
},
}
out, err := buildScript(ctx, client, choco, artifacts)
require.NoError(t, err)
golden.RequireEqualExt(t, out, ".ps1")
}