1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pkg/config/config_archive_files_test.go
fredbi 8d6ef40020
feat(yaml): upgraded from yaml.v2 to yaml.v3 (#3004)
* chore(yaml): upgraded from yaml.v2 to yaml.v3

* provided internal package to take care of backward
  compatible settings:
    * UnmarshalStrict method
    * mute io.EOF unmarshaling errors
    * marshal indenting with 2 chars
* adapted unit tests to new yaml v3

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

* fixed failing tests

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2022-03-29 14:00:53 -03:00

95 lines
1.6 KiB
Go

package config
import (
"fmt"
"testing"
"time"
"github.com/goreleaser/goreleaser/internal/yaml"
"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{
{Source: "./script.sh"},
}, 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{
{Source: "./script.sh"},
{
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",
Mode: 0o644,
MTime: now,
},
},
}, actual.Files)
}