|
|
|
@ -21,6 +21,8 @@ import (
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const NonExistingFileName = "no_such_file.txt"
|
|
|
|
|
|
|
|
|
|
var cases = []struct {
|
|
|
|
|
path, data string
|
|
|
|
|
}{
|
|
|
|
@ -46,15 +48,30 @@ func TestNewFiles(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i, f := range cases {
|
|
|
|
|
if got := string(files.GetBytes(f.path)); got != f.data {
|
|
|
|
|
gotBytes, err := files.GetBytes(f.path)
|
|
|
|
|
got := string(gotBytes)
|
|
|
|
|
if err != nil || got != f.data {
|
|
|
|
|
t.Errorf("%d: expected %q, got %q", i, f.data, got)
|
|
|
|
|
}
|
|
|
|
|
if got := files.Get(f.path); got != f.data {
|
|
|
|
|
|
|
|
|
|
gotBytes, err = files.GetBytes(f.path)
|
|
|
|
|
got = string(gotBytes)
|
|
|
|
|
if err != nil || got != f.data {
|
|
|
|
|
t.Errorf("%d: expected %q, got %q", i, f.data, got)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetNonExistingFile(t *testing.T) {
|
|
|
|
|
as := assert.New(t)
|
|
|
|
|
|
|
|
|
|
f := getTestFiles()
|
|
|
|
|
|
|
|
|
|
content, err := f.Get(NonExistingFileName)
|
|
|
|
|
as.Empty(content)
|
|
|
|
|
as.Error(err, "not included")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFileGlob(t *testing.T) {
|
|
|
|
|
as := assert.New(t)
|
|
|
|
|
|
|
|
|
@ -63,18 +80,27 @@ func TestFileGlob(t *testing.T) {
|
|
|
|
|
matched := f.Glob("story/**")
|
|
|
|
|
|
|
|
|
|
as.Len(matched, 2, "Should be two files in glob story/**")
|
|
|
|
|
as.Equal("Joseph Conrad", matched.Get("story/author.txt"))
|
|
|
|
|
|
|
|
|
|
content, err := matched.Get("story/author.txt")
|
|
|
|
|
as.Equal("Joseph Conrad", content)
|
|
|
|
|
as.NoError(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestToConfig(t *testing.T) {
|
|
|
|
|
as := assert.New(t)
|
|
|
|
|
|
|
|
|
|
f := getTestFiles()
|
|
|
|
|
out := f.Glob("**/captain.txt").AsConfig()
|
|
|
|
|
out, err := f.Glob("**/captain.txt").AsConfig()
|
|
|
|
|
as.Equal("captain.txt: The Captain", out)
|
|
|
|
|
as.NoError(err)
|
|
|
|
|
|
|
|
|
|
out = f.Glob("ship/**").AsConfig()
|
|
|
|
|
out, err = f.Glob("ship/**").AsConfig()
|
|
|
|
|
as.Equal("captain.txt: The Captain\nstowaway.txt: Legatt", out)
|
|
|
|
|
as.NoError(err)
|
|
|
|
|
|
|
|
|
|
out, err = f.Glob(NonExistingFileName).AsConfig()
|
|
|
|
|
as.Empty(out)
|
|
|
|
|
as.Error(err, "must pass files")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestToSecret(t *testing.T) {
|
|
|
|
@ -82,8 +108,13 @@ func TestToSecret(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
f := getTestFiles()
|
|
|
|
|
|
|
|
|
|
out := f.Glob("ship/**").AsSecrets()
|
|
|
|
|
out, err := f.Glob("ship/**").AsSecrets()
|
|
|
|
|
as.Equal("captain.txt: VGhlIENhcHRhaW4=\nstowaway.txt: TGVnYXR0", out)
|
|
|
|
|
as.NoError(err)
|
|
|
|
|
|
|
|
|
|
out, err = f.Glob(NonExistingFileName).AsSecrets()
|
|
|
|
|
as.Empty(out)
|
|
|
|
|
as.Errorf(err, "must pass files")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLines(t *testing.T) {
|
|
|
|
@ -91,8 +122,12 @@ func TestLines(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
f := getTestFiles()
|
|
|
|
|
|
|
|
|
|
out := f.Lines("multiline/test.txt")
|
|
|
|
|
out, err := f.Lines("multiline/test.txt")
|
|
|
|
|
as.Len(out, 2)
|
|
|
|
|
|
|
|
|
|
as.Equal("bar", out[0])
|
|
|
|
|
as.NoError(err)
|
|
|
|
|
|
|
|
|
|
out, err = f.Lines(NonExistingFileName)
|
|
|
|
|
as.Nil(out)
|
|
|
|
|
as.Error(err, "must pass files")
|
|
|
|
|
}
|
|
|
|
|