1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-22 04:08:49 +02:00
goreleaser/internal/extrafiles/extra_files_test.go
Carlos Alexandro Becker 4a6693fb72
feat: replace zglob with fileglob (#1889)
* fix: replace zglob with gobwas/glob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: added missing file

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: fixed wrong assertions

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: use fileglob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* feat: update fileglob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: update fileglob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: test errors

* fix: empty file

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: update fileglob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-11-10 11:20:55 -03:00

73 lines
1.9 KiB
Go

package extrafiles
import (
"testing"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/stretchr/testify/require"
)
func TestShouldGetSpecificFile(t *testing.T) {
globs := []config.ExtraFile{
{Glob: "./testdata/file1.golden"},
}
files, err := Find(globs)
require.NoError(t, err)
require.Len(t, files, 1)
require.Equal(t, "testdata/file1.golden", files["file1.golden"])
}
func TestFailToGetSpecificFile(t *testing.T) {
globs := []config.ExtraFile{
{Glob: "./testdata/file453.golden"},
}
files, err := Find(globs)
require.EqualError(t, err, "globbing failed for pattern ./testdata/file453.golden: matching \"testdata/file453.golden\": file does not exist")
require.Empty(t, files)
}
func TestShouldGetFilesWithSuperStar(t *testing.T) {
globs := []config.ExtraFile{
{Glob: "./**/file?.golden"},
}
files, err := Find(globs)
require.NoError(t, err)
require.Len(t, files, 3)
require.Equal(t, "testdata/file2.golden", files["file2.golden"])
require.Equal(t, "testdata/file1.golden", files["file1.golden"])
require.Equal(t, "testdata/sub/file5.golden", files["file5.golden"])
}
func TestShouldGetAllFilesWithGoldenExtension(t *testing.T) {
globs := []config.ExtraFile{
{Glob: "./testdata/*.golden"},
}
files, err := Find(globs)
require.NoError(t, err)
require.Len(t, files, 2)
require.Equal(t, "testdata/file1.golden", files["file1.golden"])
require.Equal(t, "testdata/file2.golden", files["file2.golden"])
}
func TestShouldGetAllFilesInsideTestdata(t *testing.T) {
globs := []config.ExtraFile{
{Glob: "./testdata/*"},
}
files, err := Find(globs)
require.NoError(t, err)
require.Len(t, files, 4)
require.Equal(t, "testdata/file1.golden", files["file1.golden"])
require.Equal(t, "testdata/file2.golden", files["file2.golden"])
require.Equal(t, "testdata/file3.gold", files["file3.gold"])
require.Equal(t, "testdata/sub/file5.golden", files["file5.golden"])
}