2018-08-05 10:23:39 -03:00
|
|
|
package archive
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2020-10-06 09:48:04 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-08-05 10:23:39 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestArchive(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
folder := t.TempDir()
|
2018-08-05 10:23:39 -03:00
|
|
|
empty, err := os.Create(folder + "/empty.txt")
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
2021-04-25 11:34:40 -03:00
|
|
|
require.NoError(t, empty.Close())
|
2021-04-25 14:20:49 -03:00
|
|
|
require.NoError(t, os.Mkdir(folder+"/folder-inside", 0o755))
|
2018-08-05 10:23:39 -03:00
|
|
|
|
2020-04-13 08:53:03 -04:00
|
|
|
for _, format := range []string{"tar.gz", "zip", "gz", "tar.xz", "willbeatargzanyway"} {
|
2019-02-07 12:12:20 -02:00
|
|
|
format := format
|
|
|
|
t.Run(format, func(t *testing.T) {
|
2020-12-29 15:40:21 +00:00
|
|
|
file, err := os.Create(folder + "/folder." + format)
|
|
|
|
require.NoError(t, err)
|
2021-04-25 14:20:49 -03:00
|
|
|
archive := New(file)
|
2021-04-25 11:34:40 -03:00
|
|
|
t.Cleanup(func() {
|
|
|
|
require.NoError(t, archive.Close())
|
|
|
|
require.NoError(t, file.Close())
|
|
|
|
})
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, archive.Add("empty.txt", empty.Name()))
|
|
|
|
require.Error(t, archive.Add("dont.txt", empty.Name()+"_nope"))
|
2019-02-07 12:12:20 -02:00
|
|
|
})
|
2018-08-05 10:23:39 -03:00
|
|
|
}
|
|
|
|
}
|