Esempio n. 1
0
func TestProjectFactoryFileArgMayContainMultipleFiles(t *testing.T) {
	sep := string(os.PathListSeparator)
	fileCases := []struct {
		requested []string
		available []string
		expected  []string
	}{
		{
			requested: []string{},
			available: []string{"docker-compose.yml"},
			expected:  []string{"docker-compose.yml"},
		},
		{
			requested: []string{},
			available: []string{"docker-compose.yml", "docker-compose.override.yml"},
			expected:  []string{"docker-compose.yml", "docker-compose.override.yml"},
		},
		{
			requested: []string{"one.yml"},
			available: []string{"one.yml"},
			expected:  []string{"one.yml"},
		},
		{
			requested: []string{"one.yml"},
			available: []string{"docker-compose.yml", "one.yml"},
			expected:  []string{"one.yml"},
		},
		{
			requested: []string{"one.yml", "two.yml", "three.yml"},
			available: []string{"one.yml", "two.yml", "three.yml"},
			expected:  []string{"one.yml", "two.yml", "three.yml"},
		},
		{
			requested: []string{"one.yml" + sep + "two.yml" + sep + "three.yml"},
			available: []string{"one.yml", "two.yml", "three.yml"},
			expected:  []string{"one.yml", "two.yml", "three.yml"},
		},
		{
			requested: []string{"one.yml" + sep + "two.yml", "three.yml" + sep + "four.yml"},
			available: []string{"one.yml", "two.yml", "three.yml", "four.yml"},
			expected:  []string{"one.yml", "two.yml", "three.yml", "four.yml"},
		},
		{
			requested: []string{"one.yml", "two.yml" + sep + "three.yml"},
			available: []string{"one.yml", "two.yml", "three.yml"},
			expected:  []string{"one.yml", "two.yml", "three.yml"},
		},
	}

	for _, fileCase := range fileCases {
		tmpDir, err := ioutil.TempDir("", "project-factory-test")
		if err != nil {
			t.Fatal(err)
		}
		defer os.RemoveAll(tmpDir)
		if err = os.Chdir(tmpDir); err != nil {
			t.Fatal(err)
		}

		for _, file := range fileCase.available {
			ioutil.WriteFile(file, []byte(`hello:
    image: busybox`), 0700)
		}
		globalSet := flag.NewFlagSet("test", 0)
		// Set the project-name flag
		globalSet.String("project-name", "example", "doc")
		// Set the compose file flag
		fcr := cli.StringSlice(fileCase.requested)
		globalSet.Var(&fcr, "file", "doc")
		c := cli.NewContext(nil, globalSet, nil)
		factory := &ProjectFactory{}
		p, err := factory.Create(c)
		if err != nil {
			t.Fatal(err)
		}

		for i, v := range p.(*project.Project).Files {
			if v != fileCase.expected[i] {
				t.Fatalf("requested %s, available %s, expected %s, got %s",
					fileCase.requested, fileCase.available, fileCase.expected, p.(*project.Project).Files)
			}
		}
	}
}
Esempio n. 2
0
		Name:   "advertise, addr",
		Usage:  "Address of the Docker Engine joining the cluster. Swarm manager(s) MUST be able to reach the Docker Engine at this address.",
		EnvVar: "SWARM_ADVERTISE",
	}
	flJoinRandomDelay = cli.StringFlag{
		Name:  "delay",
		Value: "0s",
		Usage: "add a random delay in [0s,delay] to avoid synchronized registration",
	}
	flManageAdvertise = cli.StringFlag{
		Name:   "advertise, addr",
		Usage:  "Address of the swarm manager joining the cluster. Other swarm manager(s) MUST be able to reach the swarm manager at this address.",
		EnvVar: "SWARM_ADVERTISE",
	}
	// hack for go vet
	flHostsValue = cli.StringSlice([]string{"tcp://127.0.0.1:2375"})

	flHosts = cli.StringSliceFlag{
		Name:   "host, H",
		Value:  &flHostsValue,
		Usage:  "ip/socket to listen on",
		EnvVar: "SWARM_HOST",
	}
	flHeartBeat = cli.StringFlag{
		Name:  "heartbeat",
		Value: "60s",
		Usage: "period between each heartbeat",
	}
	flTTL = cli.StringFlag{
		Name:  "ttl",
		Value: "180s",