github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/cli/command/stack/loader/loader_test.go (about)

     1  package loader
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"strings"
     7  	"testing"
     8  
     9  	"gotest.tools/assert"
    10  	is "gotest.tools/assert/cmp"
    11  	"gotest.tools/fs"
    12  )
    13  
    14  func TestGetConfigDetails(t *testing.T) {
    15  	content := `
    16  version: "3.0"
    17  services:
    18    foo:
    19      image: alpine:3.5
    20  `
    21  	file := fs.NewFile(t, "test-get-config-details", fs.WithContent(content))
    22  	defer file.Remove()
    23  
    24  	details, err := getConfigDetails([]string{file.Path()}, nil)
    25  	assert.NilError(t, err)
    26  	assert.Check(t, is.Equal(filepath.Dir(file.Path()), details.WorkingDir))
    27  	assert.Assert(t, is.Len(details.ConfigFiles, 1))
    28  	assert.Check(t, is.Equal("3.0", details.ConfigFiles[0].Config["version"]))
    29  	assert.Check(t, is.Len(details.Environment, len(os.Environ())))
    30  }
    31  
    32  func TestGetConfigDetailsStdin(t *testing.T) {
    33  	content := `
    34  version: "3.0"
    35  services:
    36    foo:
    37      image: alpine:3.5
    38  `
    39  	details, err := getConfigDetails([]string{"-"}, strings.NewReader(content))
    40  	assert.NilError(t, err)
    41  	cwd, err := os.Getwd()
    42  	assert.NilError(t, err)
    43  	assert.Check(t, is.Equal(cwd, details.WorkingDir))
    44  	assert.Assert(t, is.Len(details.ConfigFiles, 1))
    45  	assert.Check(t, is.Equal("3.0", details.ConfigFiles[0].Config["version"]))
    46  	assert.Check(t, is.Len(details.Environment, len(os.Environ())))
    47  }