Skip to content

Commit

Permalink
test: fix broken tests
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Apr 25, 2022
1 parent c03efa7 commit a351254
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion internal/builders/golang/build_test.go
Expand Up @@ -316,6 +316,7 @@ func TestBuild(t *testing.T) {
"linux_mips64le_softfloat",
},
GoBinary: "go",
Command: "build",
BuildDetails: config.BuildDetails{
Asmflags: []string{".=", "all="},
Gcflags: []string{"all="},
Expand Down Expand Up @@ -494,6 +495,7 @@ func TestBuildCodeInSubdir(t *testing.T) {
runtimeTarget,
},
GoBinary: "go",
Command: "build",
},
},
}
Expand Down Expand Up @@ -521,6 +523,7 @@ func TestBuildWithDotGoDir(t *testing.T) {
Binary: "foo",
Targets: []string{runtimeTarget},
GoBinary: "go",
Command: "build",
},
},
}
Expand Down Expand Up @@ -549,6 +552,7 @@ func TestBuildFailed(t *testing.T) {
runtimeTarget,
},
GoBinary: "go",
Command: "build",
},
},
}
Expand Down Expand Up @@ -773,6 +777,7 @@ import _ "github.com/goreleaser/goreleaser"
runtimeTarget,
},
GoBinary: "go",
Command: "build",
},
},
}
Expand Down Expand Up @@ -800,6 +805,7 @@ func TestRunPipeWithMainFuncNotInMainGoFile(t *testing.T) {
runtimeTarget,
},
GoBinary: "go",
Command: "build",
},
},
}
Expand Down Expand Up @@ -954,6 +960,7 @@ func TestBuildModTimestamp(t *testing.T) {
},
ModTimestamp: fmt.Sprintf("%d", modTime.Unix()),
GoBinary: "go",
Command: "build",
},
},
}
Expand Down Expand Up @@ -1006,7 +1013,7 @@ func TestBuildGoBuildLine(t *testing.T) {
ctx.Git.Commit = "aaa"

line, err := buildGoBuildLine(ctx, config.Builds[0], api.Options{
Path: "foo",
Path: config.Builds[0].Binary,
Goos: "linux",
Goarch: "amd64",
}, &artifact.Artifact{}, []string{})
Expand All @@ -1024,7 +1031,9 @@ func TestBuildGoBuildLine(t *testing.T) {
Tags: []string{"tag1", "tag2"},
Ldflags: []string{"ldflag1", "ldflag2"},
},
Binary: "foo",
GoBinary: "go",
Command: "build",
}, []string{
"go", "build",
"-flag1", "-flag2",
Expand Down Expand Up @@ -1060,6 +1069,8 @@ func TestBuildGoBuildLine(t *testing.T) {
},
},
GoBinary: "go",
Binary: "foo",
Command: "build",
}, []string{
"go", "build",
"-flag3",
Expand All @@ -1075,16 +1086,32 @@ func TestBuildGoBuildLine(t *testing.T) {
requireEqualCmd(t, config.Build{
Main: ".",
GoBinary: "go",
Command: "build",
Binary: "foo",
}, strings.Fields("go build -o foo ."))
})

t.Run("test", func(t *testing.T) {
requireEqualCmd(t, config.Build{
Main: ".",
GoBinary: "go",
Command: "test",
Binary: "foo.test",
BuildDetails: config.BuildDetails{
Flags: []string{"-c"},
},
}, strings.Fields("go test -c -o foo.test ."))
})

t.Run("ldflags1", func(t *testing.T) {
requireEqualCmd(t, config.Build{
Main: ".",
BuildDetails: config.BuildDetails{
Ldflags: []string{"-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.builtBy=goreleaser"},
},
GoBinary: "go",
Command: "build",
Binary: "foo",
}, []string{
"go", "build",
"-ldflags=-s -w -X main.version=1.2.3 -X main.commit=aaa -X main.builtBy=goreleaser",
Expand All @@ -1099,6 +1126,8 @@ func TestBuildGoBuildLine(t *testing.T) {
Ldflags: []string{"-s -w", "-X main.version={{.Version}}"},
},
GoBinary: "go",
Binary: "foo",
Command: "build",
}, []string{"go", "build", "-ldflags=-s -w -X main.version=1.2.3", "-o", "foo", "."})
})
}
Expand Down

0 comments on commit a351254

Please sign in to comment.