mirror of https://github.com/docker/compose.git
Add unit tests version of migration tests instead of e2e one
Signed-off-by: Guillaume Lours <guillaume.lours@docker.com> Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
4bbe3f1589
commit
07a57469db
|
@ -213,6 +213,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j
|
|||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/miekg/pkcs11 v1.0.3 h1:iMwmD7I5225wv84WxIG/bmxz9AXjWvTWIbM/TYHvWtw=
|
||||
github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package amazon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/ecs-plugin/pkg/compose"
|
||||
"gotest.tools/v3/golden"
|
||||
)
|
||||
|
||||
func TestSimpleConvert(t *testing.T) {
|
||||
options := compose.ProjectOptions{
|
||||
Name: t.Name(),
|
||||
ConfigPaths: []string{"testdata/input/simple-single-service.yaml"},
|
||||
}
|
||||
result := convertResultAsString(t, options, "TestCluster")
|
||||
expected := "simple/simple-cloudformation-conversion.golden"
|
||||
golden.Assert(t, result, expected)
|
||||
}
|
||||
|
||||
func TestSimpleWithOverrides(t *testing.T) {
|
||||
options := compose.ProjectOptions{
|
||||
Name: t.Name(),
|
||||
ConfigPaths: []string{"testdata/input/simple-single-service.yaml", "testdata/input/simple-single-service-with-overrides.yaml"},
|
||||
}
|
||||
result := convertResultAsString(t, options, "TestCluster")
|
||||
expected := "simple/simple-cloudformation-with-overrides-conversion.golden"
|
||||
golden.Assert(t, result, expected)
|
||||
}
|
||||
|
||||
func convertResultAsString(t *testing.T, options compose.ProjectOptions, clusterName string) string {
|
||||
project, err := compose.ProjectFromOptions(&options)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
client, err := NewClient("", clusterName, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
result, err := client.Convert(project)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
resultAsJSON, err := result.JSON()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
return fmt.Sprintf("%s\n", string(resultAsJSON))
|
||||
}
|
|
@ -7,12 +7,12 @@ import (
|
|||
|
||||
type ProjectOptions struct {
|
||||
ConfigPaths []string
|
||||
name string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (o *ProjectOptions) AddFlags(flags *pflag.FlagSet) {
|
||||
flags.StringArrayVarP(&o.ConfigPaths, "file", "f", nil, "Specify an alternate compose file")
|
||||
flags.StringVarP(&o.name, "project-name", "n", "", "Specify an alternate project name (default: directory name)")
|
||||
flags.StringVarP(&o.Name, "project-name", "n", "", "Specify an alternate project name (default: directory name)")
|
||||
}
|
||||
|
||||
type ProjectFunc func(project *Project, args []string) error
|
||||
|
|
|
@ -40,7 +40,7 @@ func ProjectFromOptions(options *ProjectOptions) (*Project, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
name := options.name
|
||||
name := options.Name
|
||||
if name == "" {
|
||||
name = os.Getenv("COMPOSE_PROJECT_NAME")
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@ import (
|
|||
|
||||
func Test_project_name(t *testing.T) {
|
||||
p, err := ProjectFromOptions(&ProjectOptions{
|
||||
name: "my_project",
|
||||
Name: "my_project",
|
||||
ConfigPaths: []string{"testdata/simple/compose.yaml"},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, p.Name, "my_project")
|
||||
|
||||
p, err = ProjectFromOptions(&ProjectOptions{
|
||||
name: "",
|
||||
Name: "",
|
||||
ConfigPaths: []string{"testdata/simple/compose.yaml"},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
@ -24,7 +24,7 @@ func Test_project_name(t *testing.T) {
|
|||
|
||||
os.Setenv("COMPOSE_PROJECT_NAME", "my_project_from_env")
|
||||
p, err = ProjectFromOptions(&ProjectOptions{
|
||||
name: "",
|
||||
Name: "",
|
||||
ConfigPaths: []string{"testdata/simple/compose.yaml"},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
@ -33,7 +33,7 @@ func Test_project_name(t *testing.T) {
|
|||
|
||||
func Test_project_from_set_of_files(t *testing.T) {
|
||||
p, err := ProjectFromOptions(&ProjectOptions{
|
||||
name: "my_project",
|
||||
Name: "my_project",
|
||||
ConfigPaths: []string{
|
||||
"testdata/simple/compose.yaml",
|
||||
"testdata/simple/compose-with-overrides.yaml",
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/fs"
|
||||
"gotest.tools/v3/golden"
|
||||
"gotest.tools/v3/icmd"
|
||||
)
|
||||
|
||||
const (
|
||||
composeFileName = "compose.yaml"
|
||||
)
|
||||
|
||||
func TestSimpleConvert(t *testing.T) {
|
||||
cmd, cleanup := dockerCli.createTestCmd()
|
||||
defer cleanup()
|
||||
|
||||
composeYAML := golden.Get(t, "input/simple-single-service.yaml")
|
||||
tmpDir := fs.NewDir(t, t.Name(),
|
||||
fs.WithFile(composeFileName, "", fs.WithBytes(composeYAML)),
|
||||
)
|
||||
defer tmpDir.Remove()
|
||||
|
||||
cmd.Command = dockerCli.Command("ecs", "compose", "--file="+tmpDir.Join(composeFileName), "--project-name", t.Name(), "convert")
|
||||
result := icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined()
|
||||
|
||||
expected := "simple/simple-cloudformation-conversion.golden"
|
||||
golden.Assert(t, result, expected)
|
||||
}
|
||||
|
||||
func TestSimpleWithOverrides(t *testing.T) {
|
||||
cmd, cleanup := dockerCli.createTestCmd()
|
||||
defer cleanup()
|
||||
|
||||
composeYAML := golden.Get(t, "input/simple-single-service.yaml")
|
||||
overriddenComposeYAML := golden.Get(t, "input/simple-single-service-with-overrides.yaml")
|
||||
tmpDir := fs.NewDir(t, t.Name(),
|
||||
fs.WithFile(composeFileName, "", fs.WithBytes(composeYAML)),
|
||||
fs.WithFile("overriddenService.yaml", "", fs.WithBytes(overriddenComposeYAML)),
|
||||
)
|
||||
defer tmpDir.Remove()
|
||||
cmd.Command = dockerCli.Command("ecs", "compose", "--file="+tmpDir.Join(composeFileName), "--file",
|
||||
tmpDir.Join("overriddenService.yaml"), "--project-name", t.Name(), "convert")
|
||||
result := icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined()
|
||||
|
||||
expected := "simple/simple-cloudformation-with-overrides-conversion.golden"
|
||||
golden.Assert(t, result, expected)
|
||||
}
|
Loading…
Reference in New Issue