Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Add a seed for better randomness #741

Merged
merged 2 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/cnab-run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"errors"
"fmt"
"math/rand"
"os"
"time"

"github.com/docker/app/internal"
)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmd/docker-app/main.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions e2e/run_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}