1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pkg/archive/archive_test.go
Carlos Alexandro Becker 5d9110ab43
refactor: improve archive pipe (#3100)
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-05-11 21:54:28 -03:00

43 lines
1014 B
Go

package archive
import (
"io"
"os"
"testing"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/stretchr/testify/require"
)
func TestArchive(t *testing.T) {
folder := t.TempDir()
empty, err := os.Create(folder + "/empty.txt")
require.NoError(t, err)
require.NoError(t, empty.Close())
require.NoError(t, os.Mkdir(folder+"/folder-inside", 0o755))
for _, format := range []string{"tar.gz", "zip", "gz", "tar.xz", "tar"} {
format := format
t.Run(format, func(t *testing.T) {
archive, err := New(io.Discard, format)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, archive.Close())
})
require.NoError(t, archive.Add(config.File{
Source: empty.Name(),
Destination: "empty.txt",
}))
require.Error(t, archive.Add(config.File{
Source: empty.Name() + "_nope",
Destination: "dont.txt",
}))
})
}
t.Run("7z", func(t *testing.T) {
_, err := New(io.Discard, "7z")
require.EqualError(t, err, "invalid archive format: 7z")
})
}