Example #1
0
func run(executable string, args []string) error {
	config, err := config.Load()
	if err != nil {
		return err
	}

	env, err := dockerEnv(config)
	if err != nil {
		return err
	}

	cmd := exec.Command(executable, args...)
	cmd.Stdin = os.Stdin
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	cmd.Env = append(os.Environ(), env...)

	return cmd.Run()
}
Example #2
0
func TestUseMachine(t *testing.T) {
	tests := []struct {
		args           []string
		expectedConfig config.Config
	}{
		{[]string{"default"}, config.Config{
			Type:    "machine",
			Machine: "default",
		}},
		{[]string{"other"}, config.Config{
			Type:    "machine",
			Machine: "other",
		}},
		{[]string{"local"}, config.Config{
			Type: "local",
		}},
		{[]string{"tcp://192.168.99.100:2376", "~/.docker/certs"}, config.Config{
			Type:     "url",
			Url:      "tcp://192.168.99.100:2376",
			CertPath: "~/.docker/certs",
		}},
		{[]string{"tcp://192.168.99.150:2376"}, config.Config{
			Type: "url",
			Url:  "tcp://192.168.99.150:2376",
		}},
	}

	for _, test := range tests {
		os.Args = append([]string{"marcel", "use"}, test.args...)

		main()

		config, err := config.Load()

		assert.Equal(t, test.expectedConfig, *config)
		assert.NoError(t, err)
	}
}