2021-07-22 03:09:02 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-03-29 19:00:53 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/yaml"
|
2021-07-22 03:09:02 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestArchiveFiles_justString(t *testing.T) {
|
|
|
|
var actual Archive
|
|
|
|
|
|
|
|
err := yaml.UnmarshalStrict([]byte(`
|
|
|
|
files:
|
|
|
|
- ./script.sh
|
|
|
|
`), &actual)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []File{
|
2021-07-26 13:38:14 +02:00
|
|
|
{Source: "./script.sh"},
|
2021-07-22 03:09:02 +02:00
|
|
|
}, actual.Files)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestArchiveFiles_stringFiles(t *testing.T) {
|
|
|
|
var actual Archive
|
|
|
|
|
|
|
|
err := yaml.UnmarshalStrict([]byte(`
|
|
|
|
files:
|
|
|
|
- ./script.sh
|
|
|
|
- src: ./foo
|
|
|
|
dst: ./bar
|
|
|
|
info:
|
|
|
|
owner: carlos
|
|
|
|
group: users
|
|
|
|
`), &actual)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []File{
|
2021-07-26 13:38:14 +02:00
|
|
|
{Source: "./script.sh"},
|
2021-07-22 03:09:02 +02:00
|
|
|
{
|
|
|
|
Source: "./foo",
|
|
|
|
Destination: "./bar",
|
|
|
|
Info: FileInfo{
|
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, actual.Files)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestArchiveFiles_complex(t *testing.T) {
|
|
|
|
var actual Archive
|
|
|
|
now := time.Now().UTC().Truncate(time.Second)
|
|
|
|
|
|
|
|
// 2021-07-17T15:14:10.264931-03:00
|
|
|
|
|
|
|
|
err := yaml.UnmarshalStrict([]byte(fmt.Sprintf(`
|
|
|
|
files:
|
|
|
|
- src: ./foo
|
|
|
|
dst: ./bar
|
|
|
|
info:
|
|
|
|
owner: carlos
|
|
|
|
group: users
|
|
|
|
- src: ./foobar
|
|
|
|
dst: ./barzaz
|
|
|
|
info:
|
|
|
|
owner: carlos
|
|
|
|
group: users
|
|
|
|
mode: 0644
|
|
|
|
mtime: "%s"
|
|
|
|
`, now.Format(time.RFC3339Nano))), &actual)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, []File{
|
|
|
|
{
|
|
|
|
Source: "./foo",
|
|
|
|
Destination: "./bar",
|
|
|
|
Info: FileInfo{
|
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "./foobar",
|
|
|
|
Destination: "./barzaz",
|
|
|
|
Info: FileInfo{
|
|
|
|
Owner: "carlos",
|
|
|
|
Group: "users",
|
2021-07-24 04:54:13 +02:00
|
|
|
Mode: 0o644,
|
2021-07-22 03:09:02 +02:00
|
|
|
MTime: now,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, actual.Files)
|
|
|
|
}
|