Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit aaa673f

Browse files
authored
Merge pull request #741 from rumpl/random-seed
Add a seed for better randomness
2 parents 3328d80 + 2aacb5d commit aaa673f

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

cmd/cnab-run/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package main
33
import (
44
"errors"
55
"fmt"
6+
"math/rand"
67
"os"
8+
"time"
79

810
"github.com/docker/app/internal"
911
)
@@ -38,6 +40,7 @@ func getCnabAction() (cnabAction, string, error) {
3840
}
3941

4042
func main() {
43+
rand.Seed(time.Now().UnixNano())
4144
action, actionName, err := getCnabAction()
4245
if err != nil {
4346
fmt.Fprintf(os.Stderr, "Error while parsing CNAB operation: %s", err)

cmd/docker-app/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

33
import (
4+
"math/rand"
5+
"time"
6+
47
"github.com/docker/app/internal"
58
app "github.com/docker/app/internal/commands"
69
"github.com/docker/cli/cli-plugins/manager"
@@ -10,6 +13,7 @@ import (
1013
)
1114

1215
func main() {
16+
rand.Seed(time.Now().UnixNano())
1317
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
1418
cmd := app.NewRootCmd("app", dockerCli)
1519
originalPreRun := cmd.PersistentPreRunE

e2e/run_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package e2e
2+
3+
import (
4+
"path/filepath"
5+
"testing"
6+
7+
"gotest.tools/icmd"
8+
)
9+
10+
func TestRunTwice(t *testing.T) {
11+
// Test that we are indeed generating random app names
12+
// We had a problem where the second run would fail with an error
13+
// "Installation "gallant_poitras" already exists, use 'docker app update' instead"
14+
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
15+
cmd := info.configuredCmd
16+
contextPath := filepath.Join("testdata", "simple")
17+
18+
cmd.Command = dockerCli.Command("app", "build", "--tag", "myapp", contextPath)
19+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
20+
21+
cmd.Command = dockerCli.Command("app", "run", "myapp", "--set", "web_port=8080")
22+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
23+
24+
cmd.Command = dockerCli.Command("app", "run", "myapp", "--set", "web_port=8081")
25+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
26+
})
27+
}

0 commit comments

Comments
 (0)