This commit is contained in:
Guillaume Tardif 2020-06-16 17:35:21 +02:00
parent 8f6cd7c63f
commit 90acf5eddc
2 changed files with 50 additions and 6 deletions

View File

@ -1,7 +1,6 @@
package compose
import (
"errors"
"fmt"
"io/ioutil"
"os"
@ -130,12 +129,13 @@ func parseConfigs(configPaths []string) ([]types.ConfigFile, error) {
var b []byte
var err error
if f == "-" {
return []types.ConfigFile{}, errors.New("reading compose file from stdin is not supported")
b, err = ioutil.ReadAll(os.Stdin)
} else {
if _, err := os.Stat(f); err != nil {
return nil, err
}
b, err = ioutil.ReadFile(f)
}
if _, err := os.Stat(f); err != nil {
return nil, err
}
b, err = ioutil.ReadFile(f)
if err != nil {
return nil, err
}

44
compose/project_test.go Normal file
View File

@ -0,0 +1,44 @@
package compose
import (
"os"
"testing"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/suite"
)
type ComposeTest struct {
suite.Suite
}
func (suite *ComposeTest) TestParseComposeFile() {
files := []string{"../tests/composefiles/aci-demo/aci_demo_port.yaml"}
config, err := parseConfigs(files)
Expect(err).To(BeNil())
services := config[0].Config["services"].(map[string]interface{})
Expect(len(services)).To(Equal(3))
}
func (suite *ComposeTest) TestParseComposeStdin() {
files := []string{"-"}
f, err := os.Open("../tests/composefiles/aci-demo/aci_demo_port.yaml")
Expect(err).To(BeNil())
defer func() {
err := f.Close()
Expect(err).To(BeNil())
}()
oldStdin := os.Stdin
defer func() { os.Stdin = oldStdin }() // Restore original Stdin
os.Stdin = f
config, err := parseConfigs(files)
Expect(err).To(BeNil())
services := config[0].Config["services"].(map[string]interface{})
Expect(len(services)).To(Equal(3))
}
func TestComposeProject(t *testing.T) {
RegisterTestingT(t)
suite.Run(t, new(ComposeTest))
}