diff --git a/cmd/cnab-run/main.go b/cmd/cnab-run/main.go index 5333218c6..9c3ab0554 100644 --- a/cmd/cnab-run/main.go +++ b/cmd/cnab-run/main.go @@ -3,7 +3,9 @@ package main import ( "errors" "fmt" + "math/rand" "os" + "time" "github.com/docker/app/internal" ) @@ -38,6 +40,7 @@ func getCnabAction() (cnabAction, string, error) { } func main() { + rand.Seed(time.Now().UnixNano()) action, actionName, err := getCnabAction() if err != nil { fmt.Fprintf(os.Stderr, "Error while parsing CNAB operation: %s", err) diff --git a/cmd/docker-app/main.go b/cmd/docker-app/main.go index 2977c7c62..85095b2d7 100644 --- a/cmd/docker-app/main.go +++ b/cmd/docker-app/main.go @@ -1,6 +1,9 @@ package main import ( + "math/rand" + "time" + "github.com/docker/app/internal" app "github.com/docker/app/internal/commands" "github.com/docker/cli/cli-plugins/manager" @@ -10,6 +13,7 @@ import ( ) func main() { + rand.Seed(time.Now().UnixNano()) plugin.Run(func(dockerCli command.Cli) *cobra.Command { cmd := app.NewRootCmd("app", dockerCli) originalPreRun := cmd.PersistentPreRunE diff --git a/e2e/run_test.go b/e2e/run_test.go new file mode 100644 index 000000000..6220eac9f --- /dev/null +++ b/e2e/run_test.go @@ -0,0 +1,27 @@ +package e2e + +import ( + "path/filepath" + "testing" + + "gotest.tools/icmd" +) + +func TestRunTwice(t *testing.T) { + // Test that we are indeed generating random app names + // We had a problem where the second run would fail with an error + // "Installation "gallant_poitras" already exists, use 'docker app update' instead" + runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) { + cmd := info.configuredCmd + contextPath := filepath.Join("testdata", "simple") + + cmd.Command = dockerCli.Command("app", "build", "--tag", "myapp", contextPath) + icmd.RunCmd(cmd).Assert(t, icmd.Success) + + cmd.Command = dockerCli.Command("app", "run", "myapp", "--set", "web_port=8080") + icmd.RunCmd(cmd).Assert(t, icmd.Success) + + cmd.Command = dockerCli.Command("app", "run", "myapp", "--set", "web_port=8081") + icmd.RunCmd(cmd).Assert(t, icmd.Success) + }) +}