Skip to content

Commit

Permalink
test: improve more tests
Browse files Browse the repository at this point in the history
extracted from #3795
  • Loading branch information
caarlos0 committed Jun 17, 2023
1 parent 94981fb commit 163f0af
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
13 changes: 10 additions & 3 deletions internal/pipe/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package env
import (
"fmt"
"os"
"syscall"
"testing"

"github.com/goreleaser/goreleaser/internal/testctx"
Expand Down Expand Up @@ -183,7 +184,9 @@ func TestEmptyGithubEnvFile(t *testing.T) {
GitHubToken: f.Name(),
},
})
require.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load github token: open %s: permission denied", f.Name()))
err = Pipe{}.Run(ctx)
require.ErrorIs(t, err, syscall.EACCES)
require.Contains(t, err.Error(), "failed to load github token")
}

func TestEmptyGitlabEnvFile(t *testing.T) {
Expand All @@ -196,7 +199,9 @@ func TestEmptyGitlabEnvFile(t *testing.T) {
GitLabToken: f.Name(),
},
})
require.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load gitlab token: open %s: permission denied", f.Name()))
err = Pipe{}.Run(ctx)
require.ErrorIs(t, err, syscall.EACCES)
require.Contains(t, err.Error(), "failed to load gitlab token")
}

func TestEmptyGiteaEnvFile(t *testing.T) {
Expand All @@ -209,7 +214,9 @@ func TestEmptyGiteaEnvFile(t *testing.T) {
GiteaToken: f.Name(),
},
})
require.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load gitea token: open %s: permission denied", f.Name()))
err = Pipe{}.Run(ctx)
require.ErrorIs(t, err, syscall.EACCES)
require.Contains(t, err.Error(), "failed to load gitea token")
}

func TestInvalidEnvChecksSkipped(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions internal/pipe/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,4 @@ func requireEqualJSONFile(tb testing.TB, tmp, s string) {
tb.Helper()
path := filepath.Join(tmp, s)
golden.RequireEqualJSON(tb, golden.RequireReadFile(tb, path))

info, err := os.Stat(path)
require.NoError(tb, err)
require.Equal(tb, "-rw-r--r--", info.Mode().String())
}
4 changes: 2 additions & 2 deletions pkg/archive/tar/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func TestTarFile(t *testing.T) {
require.NoError(t, err)
paths = append(paths, next.Name)
if next.Name == "sub1/executable" {
ex := next.FileInfo().Mode() | 0o111
require.Equal(t, next.FileInfo().Mode().String(), ex.String())
ex := next.FileInfo().Mode()&0o111 != 0
require.True(t, ex, "expected executable permissions, got %s", next.FileInfo().Mode())
}
if next.Name == "link.txt" {
require.Equal(t, next.Linkname, "regular.txt")
Expand Down
4 changes: 2 additions & 2 deletions pkg/archive/targz/targz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func TestTarGzFile(t *testing.T) {
require.NoError(t, err)
paths = append(paths, next.Name)
if next.Name == "sub1/executable" {
ex := next.FileInfo().Mode() | 0o111
require.Equal(t, next.FileInfo().Mode().String(), ex.String())
ex := next.FileInfo().Mode()&0o111 != 0
require.True(t, ex, "expected executable permissions, got %s", next.FileInfo().Mode())
}
if next.Name == "link.txt" {
require.Equal(t, next.Linkname, "regular.txt")
Expand Down
4 changes: 2 additions & 2 deletions pkg/archive/tarxz/tarxz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func TestTarXzFile(t *testing.T) {
require.NoError(t, err)
paths = append(paths, next.Name)
if next.Name == "sub1/executable" {
ex := next.FileInfo().Mode() | 0o111
require.Equal(t, next.FileInfo().Mode().String(), ex.String())
ex := next.FileInfo().Mode()&0o111 != 0
require.True(t, ex, "expected executable permissions, got %s", next.FileInfo().Mode())
}
if next.Name == "link.txt" {
require.Equal(t, next.Linkname, "regular.txt")
Expand Down
4 changes: 2 additions & 2 deletions pkg/archive/zip/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func TestZipFile(t *testing.T) {
for i, zf := range r.File {
paths[i] = zf.Name
if zf.Name == "sub1/executable" {
ex := zf.Mode() | 0o111
require.Equal(t, zf.Mode().String(), ex.String())
ex := zf.Mode()&0o111 != 0
require.True(t, ex, "expected executable permissions, got %s", zf.Mode())
}
if zf.Name == "link.txt" {
require.True(t, zf.FileInfo().Mode()&os.ModeSymlink != 0)
Expand Down

0 comments on commit 163f0af

Please sign in to comment.