Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GOCMD = go
GOTEST = $(GOCMD) test

# renovate: datasource=github-tags depName=golangci/golangci-lint
GOLANGCI_VERSION ?= v2.1.6
GOLANGCI_VERSION ?= v2.6.2
TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools)

GOLANGCI = $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION)
Expand Down
12 changes: 4 additions & 8 deletions fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,7 @@ type Fixture struct {
}

func (f *Fixture) Is(tag string) bool {
for _, t := range f.Tags {
if t == tag {
return true
}
}

return false
return slices.Contains(f.Tags, tag)
}

func (f *Fixture) Packfile() billy.File {
Expand Down Expand Up @@ -316,7 +310,8 @@ func (f *Fixture) Clone() *Fixture {

// EnsureIsBare overrides the config file with one where bare is true.
func EnsureIsBare(fs billy.Filesystem) error {
if _, err := fs.Stat("config"); err != nil {
_, err := fs.Stat("config")
if err != nil {
return fmt.Errorf("not .git folder: %w", err)
}

Expand Down Expand Up @@ -370,6 +365,7 @@ type Fixtures []*Fixture
// Run calls test within a t.Run for each fixture in g.
func (g Fixtures) Run(t *testing.T, test func(*testing.T, *Fixture)) {
t.Helper()

for _, f := range g {
name := fmt.Sprintf("fixture run (%q, %q)", f.URL, f.Tags)
t.Run(name, func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ func TestRevFiles(t *testing.T) {

func TestAll(t *testing.T) {
t.Parallel()

fs := fixtures.All()

assert.Len(t, fs, 39)
}

func TestByTag(t *testing.T) {
t.Parallel()

tests := []struct {
tag string
len int
Expand Down
7 changes: 6 additions & 1 deletion internal/tgz/tgz.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func filemode(mode int64) (fs.FileMode, error) {
if mode < 0 {
return 0, ErrCannotBeNegative
}

if mode > math.MaxUint32 {
return 0, ErrCannotBeGreaterThanMaxUInt32
}
Expand All @@ -81,10 +82,12 @@ func unTar(fs billy.Filesystem, src *tar.Reader) error {
}

dst := header.Name

mode, err := filemode(header.Mode)
if err != nil {
return err
}

switch header.Typeflag {
case tar.TypeDir:
err := fs.MkdirAll(dst, mode)
Expand All @@ -110,6 +113,7 @@ func makeFile(fs billy.Filesystem, path string, mode os.FileMode, contents io.Re
if err != nil {
return err
}

defer func() {
errClose := w.Close()
if err == nil {
Expand All @@ -123,7 +127,8 @@ func makeFile(fs billy.Filesystem, path string, mode os.FileMode, contents io.Re
}

if fs, ok := fs.(billy.Change); ok {
if err = fs.Chmod(path, mode); err != nil {
err = fs.Chmod(path, mode)
if err != nil {
return err
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/tgz/tgz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestExtractError(t *testing.T) {
require.NoError(t, err)

source := osfs.New(d + "/fixtures")

f, err := source.Open(tc.tgz)
if tc.notFound {
require.ErrorIs(t, err, os.ErrNotExist)
Expand Down
6 changes: 4 additions & 2 deletions osfixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (
)

type OSFixture struct {
dir string
*Fixture

dir string
}

// NewOSFixture converts a Fixture which is based on embedfs, into
// an OS based fixture.
func NewOSFixture(f *Fixture, dir string) *OSFixture {
return &OSFixture{
dir: dir,
Fixture: f,
dir: dir,
}
}

Expand Down Expand Up @@ -67,6 +68,7 @@ func embedToOsfs(dir string, f billy.File) billy.File {
defer f.Close()

fs := osfs.New(dir)

out, err := fs.TempFile("", "embed")
if err != nil {
panic(err)
Expand Down