2018-01-29 16:18:43 -05:00
|
|
|
package loader
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/fs"
|
2018-01-29 16:18:43 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetConfigDetails(t *testing.T) {
|
|
|
|
content := `
|
|
|
|
version: "3.0"
|
|
|
|
services:
|
|
|
|
foo:
|
|
|
|
image: alpine:3.5
|
|
|
|
`
|
|
|
|
file := fs.NewFile(t, "test-get-config-details", fs.WithContent(content))
|
|
|
|
defer file.Remove()
|
|
|
|
|
2020-09-22 05:16:05 -04:00
|
|
|
details, err := GetConfigDetails([]string{file.Path()}, nil)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(filepath.Dir(file.Path()), details.WorkingDir))
|
|
|
|
assert.Assert(t, is.Len(details.ConfigFiles, 1))
|
|
|
|
assert.Check(t, is.Equal("3.0", details.ConfigFiles[0].Config["version"]))
|
|
|
|
assert.Check(t, is.Len(details.Environment, len(os.Environ())))
|
2018-01-29 16:18:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetConfigDetailsStdin(t *testing.T) {
|
|
|
|
content := `
|
|
|
|
version: "3.0"
|
|
|
|
services:
|
|
|
|
foo:
|
|
|
|
image: alpine:3.5
|
|
|
|
`
|
2020-09-22 05:16:05 -04:00
|
|
|
details, err := GetConfigDetails([]string{"-"}, strings.NewReader(content))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.NilError(t, err)
|
2018-01-29 16:18:43 -05:00
|
|
|
cwd, err := os.Getwd()
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(cwd, details.WorkingDir))
|
|
|
|
assert.Assert(t, is.Len(details.ConfigFiles, 1))
|
|
|
|
assert.Check(t, is.Equal("3.0", details.ConfigFiles[0].Config["version"]))
|
|
|
|
assert.Check(t, is.Len(details.Environment, len(os.Environ())))
|
2018-01-29 16:18:43 -05:00
|
|
|
}
|