2020-05-25 20:07:40 +02:00
|
|
|
package extrafiles
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
2020-10-06 14:48:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-05-25 20:07:40 +02:00
|
|
|
)
|
|
|
|
|
2020-11-10 16:20:55 +02:00
|
|
|
func TestShouldGetSpecificFile(t *testing.T) {
|
2020-05-25 20:07:40 +02:00
|
|
|
globs := []config.ExtraFile{
|
|
|
|
{Glob: "./testdata/file1.golden"},
|
|
|
|
}
|
|
|
|
|
|
|
|
files, err := Find(globs)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2020-11-10 16:20:55 +02:00
|
|
|
require.Len(t, files, 1)
|
2020-05-25 20:07:40 +02:00
|
|
|
|
2020-11-10 16:20:55 +02:00
|
|
|
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)
|
2021-03-01 19:19:13 +02:00
|
|
|
require.EqualError(t, err, "globbing failed for pattern ./testdata/file453.golden: matching \"./testdata/file453.golden\": file does not exist")
|
2020-11-10 16:20:55 +02:00
|
|
|
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"])
|
2020-05-25 20:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldGetAllFilesWithGoldenExtension(t *testing.T) {
|
|
|
|
globs := []config.ExtraFile{
|
|
|
|
{Glob: "./testdata/*.golden"},
|
|
|
|
}
|
|
|
|
|
|
|
|
files, err := Find(globs)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2020-11-10 16:20:55 +02:00
|
|
|
require.Len(t, files, 2)
|
2020-05-25 20:07:40 +02:00
|
|
|
|
2020-11-10 16:20:55 +02:00
|
|
|
require.Equal(t, "testdata/file1.golden", files["file1.golden"])
|
|
|
|
require.Equal(t, "testdata/file2.golden", files["file2.golden"])
|
2020-05-25 20:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldGetAllFilesInsideTestdata(t *testing.T) {
|
|
|
|
globs := []config.ExtraFile{
|
|
|
|
{Glob: "./testdata/*"},
|
|
|
|
}
|
|
|
|
|
|
|
|
files, err := Find(globs)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2020-11-10 16:20:55 +02:00
|
|
|
require.Len(t, files, 4)
|
2020-05-25 20:07:40 +02:00
|
|
|
|
2020-11-10 16:20:55 +02:00
|
|
|
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"])
|
2020-05-25 20:07:40 +02:00
|
|
|
}
|