Example #1
0
func (s *OptionsSuite) TestEmptyPipelineOptionsEmptyDir() {
	tmpDir, err := ioutil.TempDir("", "empty-directory")
	s.Nil(err)
	defer os.RemoveAll(tmpDir)

	basename := filepath.Base(tmpDir)
	currentUser, err := user.Current()
	s.Nil(err)
	username := currentUser.Username

	// Target the path
	args := defaultArgs(tmpDir)
	test := func(c *cli.Context) {
		opts, err := core.NewPipelineOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal(basename, opts.ApplicationID)
		s.Equal(basename, opts.ApplicationName)
		s.Equal(username, opts.ApplicationOwnerName)
		s.Equal(username, opts.ApplicationStartedByName)
		s.Equal(tmpDir, opts.ProjectPath)
		s.Equal(basename, opts.ProjectID)
		// Pretty much all the git stuff should be empty
		s.Equal("", opts.GitBranch)
		s.Equal("", opts.GitCommit)
		s.Equal("", opts.GitDomain)
		s.Equal(username, opts.GitOwner)
		s.Equal("", opts.GitRepository)
		cmd.DumpOptions(opts)
	}
	run(s, globalFlags, pipelineFlags, test, args)
}
Example #2
0
func (s *OptionsSuite) TestGuessAuthToken() {
	tmpFile, err := ioutil.TempFile("", "test-auth-token")
	s.Nil(err)

	token := uuid.NewRandom().String()
	_, err = tmpFile.Write([]byte(token))
	s.Nil(err)

	tokenStore := tmpFile.Name()
	defer os.Remove(tokenStore)
	defer tmpFile.Close()

	args := []string{
		"wercker",
		"--auth-token-store", tokenStore,
		"test",
	}

	test := func(c *cli.Context) {
		opts, err := core.NewGlobalOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal(token, opts.AuthToken)
	}

	run(s, globalFlags, emptyFlags, test, args)
}
Example #3
0
func (s *OptionsSuite) TestReporterOptions() {
	args := defaultArgs(
		"--report",
		"--wercker-host", "http://example.com/wercker-host",
		"--wercker-token", "test-token",
	)
	test := func(c *cli.Context) {
		e := emptyEnv()
		gOpts, err := core.NewGlobalOptions(util.NewCLISettings(c), e)
		opts, err := core.NewReporterOptions(util.NewCLISettings(c), e, gOpts)
		s.Nil(err)
		s.Equal(true, opts.ShouldReport)
		s.Equal("http://example.com/wercker-host", opts.ReporterHost)
		s.Equal("test-token", opts.ReporterKey)
	}
	run(s, globalFlags, pipelineFlags, test, args)
}
Example #4
0
func (s *OptionsSuite) TestKeenOptions() {
	args := defaultArgs(
		"--keen-metrics",
		"--keen-project-id", "test-id",
		"--keen-project-write-key", "test-key",
	)
	test := func(c *cli.Context) {
		e := emptyEnv()
		gOpts, err := core.NewGlobalOptions(util.NewCLISettings(c), e)
		opts, err := core.NewKeenOptions(util.NewCLISettings(c), e, gOpts)
		s.Nil(err)
		s.Equal(true, opts.ShouldKeenMetrics)
		s.Equal("test-key", opts.KeenProjectWriteKey)
		s.Equal("test-id", opts.KeenProjectID)
	}
	run(s, globalFlags, pipelineFlags, test, args)
}
Example #5
0
func (s *OptionsSuite) TestTagEscaping() {
	args := defaultArgs("--tag", "feature/foo")
	test := func(c *cli.Context) {
		opts, err := core.NewPipelineOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal("feature_foo", opts.Tag)
	}
	run(s, globalFlags, pipelineFlags, test, args)
}
Example #6
0
func (s *OptionsSuite) TestDeployOptions() {
	args := defaultArgs("--run-id", "fake-deploy-id")
	test := func(c *cli.Context) {
		opts, err := core.NewDeployOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal("fake-deploy-id", opts.RunID)
	}
	run(s, globalFlags, pipelineFlags, test, args)
}
Example #7
0
func (s *OptionsSuite) TestEmptyBuildOptions() {
	args := defaultArgs()
	test := func(c *cli.Context) {
		opts, err := core.NewBuildOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.NotEqual("", opts.RunID)
		s.Equal(opts.RunID, opts.RunID)
	}
	run(s, globalFlags, pipelineFlags, test, args)
}
Example #8
0
func (s *OptionsSuite) TestBuildOptions() {
	args := defaultArgs("--build-id", "fake-build-id")
	test := func(c *cli.Context) {
		opts, err := core.NewBuildOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal("fake-build-id", opts.PipelineID)
		s.Equal("fake-build-id", opts.BuildID)
		s.Equal("", opts.DeployID)
	}
	run(s, globalFlags, pipelineFlags, test, args)
}
Example #9
0
func (s *OptionsSuite) TestGlobalOptions() {
	args := defaultArgs()
	test := func(c *cli.Context) {
		opts, err := core.NewGlobalOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal(true, opts.Debug)
		s.Equal("http://example.com/base-url", opts.BaseURL)
		s.Equal("test-token", opts.AuthToken)
		s.Equal("/tmp/.wercker/test-token", opts.AuthTokenStore)
	}
	run(s, globalFlags, emptyFlags, test, args)
}
Example #10
0
func (s *OptionsSuite) TestReporterMissingOptions() {
	test := func(c *cli.Context) {
		e := emptyEnv()
		gOpts, err := core.NewGlobalOptions(util.NewCLISettings(c), e)
		_, err = core.NewReporterOptions(util.NewCLISettings(c), e, gOpts)
		s.NotNil(err)
	}

	missingHost := defaultArgs(
		"--report",
		"--wercker-token", "test-token",
	)

	missingKey := defaultArgs(
		"--report",
		"--wercker-host", "http://example.com/wercker-host",
	)

	run(s, globalFlags, cmd.ReporterFlags, test, missingHost)
	run(s, globalFlags, cmd.ReporterFlags, test, missingKey)
}
Example #11
0
func (s *OptionsSuite) TestKeenMissingOptions() {
	test := func(c *cli.Context) {
		e := emptyEnv()
		gOpts, err := core.NewGlobalOptions(util.NewCLISettings(c), e)
		_, err = core.NewKeenOptions(util.NewCLISettings(c), e, gOpts)
		s.NotNil(err)
	}

	missingID := defaultArgs(
		"--keen-metrics",
		"--keen-project-write-key", "test-key",
	)

	missingKey := defaultArgs(
		"--keen-metrics",
		"--keen-project-id", "test-id",
	)

	run(s, globalFlags, cmd.KeenFlags, test, missingID)
	run(s, globalFlags, cmd.KeenFlags, test, missingKey)
}
Example #12
0
func (s *OptionsSuite) TestWorkingDirCWD() {
	args := defaultArgs()
	cwd, err := filepath.Abs(".")
	s.Nil(err)

	test := func(c *cli.Context) {
		opts, err := core.NewPipelineOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal(filepath.Join(cwd, ".wercker"), opts.WorkingDir)
	}

	run(s, globalFlags, pipelineFlags, test, args)
}
Example #13
0
func (s *OptionsSuite) TestWorkingDir() {
	tempDir, err := ioutil.TempDir("", "wercker-test-")
	s.Nil(err)
	defer os.RemoveAll(tempDir)

	args := defaultArgs("--working-dir", tempDir)

	test := func(c *cli.Context) {
		opts, err := core.NewPipelineOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal(tempDir, opts.WorkingDir)
	}

	run(s, globalFlags, pipelineFlags, test, args)
}
Example #14
0
func (s *OptionsSuite) TestWorkingDirGetsSet() {
	tempDir, err := ioutil.TempDir("", "wercker-test-")
	s.Nil(err)
	defer os.RemoveAll(tempDir)

	// This ignores the _build part, we're only concerned about the working dir
	args := defaultArgs("--build-dir", filepath.Join(tempDir, "_build"))

	test := func(c *cli.Context) {
		opts, err := core.NewPipelineOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal(tempDir, opts.WorkingDir)
	}

	run(s, globalFlags, pipelineFlags, test, args)
}
Example #15
0
func (b *DockerBuilder) getOptions(env *util.Environment, config *core.BoxConfig) (*core.PipelineOptions, error) {
	c, err := b.configURL(config)
	if err != nil {
		return nil, err
	}
	servicePath := filepath.Join(c.Host, c.Path)
	if !filepath.IsAbs(servicePath) {
		servicePath, err = filepath.Abs(
			filepath.Join(b.options.ProjectPath, servicePath))
		if err != nil {
			return nil, err
		}
	}

	flagSet := func(name string, flags []cli.Flag) *flag.FlagSet {
		set := flag.NewFlagSet(name, flag.ContinueOnError)

		for _, f := range flags {
			f.Apply(set)
		}
		return set
	}

	set := flagSet("runservice", FlagsFor(PipelineFlagSet, WerckerInternalFlagSet))
	args := []string{
		servicePath,
	}
	if err := set.Parse(args); err != nil {
		return nil, err
	}
	ctx := cli.NewContext(nil, set, set)
	settings := util.NewCLISettings(ctx)
	newOptions, err := core.NewBuildOptions(settings, env)
	if err != nil {
		return nil, err
	}

	newOptions.GlobalOptions = b.options.GlobalOptions
	newOptions.ShouldCommit = true
	newOptions.PublishPorts = b.options.PublishPorts
	// TODO(termie): PACKAGING these moved
	// newOptions.DockerLocal = true
	// newOptions.DockerOptions = s.dockerOptions
	newOptions.Pipeline = c.Fragment
	return newOptions, nil
}
Example #16
0
	"golang.org/x/sys/unix"
)

var (
	cliLogger    = util.RootLogger().WithField("Logger", "CLI")
	buildCommand = cli.Command{
		Name:      "build",
		ShortName: "b",
		Usage:     "build a project",
		Action: func(c *cli.Context) {
			envfile := c.GlobalString("environment")
			_ = godotenv.Load(envfile)

			env := util.NewEnvironment(os.Environ()...)

			settings := util.NewCLISettings(c)
			opts, err := core.NewBuildOptions(settings, env)
			if err != nil {
				cliLogger.Errorln("Invalid options\n", err)
				os.Exit(1)
			}
			dockerOptions, err := dockerlocal.NewDockerOptions(settings, env)
			if err != nil {
				cliLogger.Errorln("Invalid options\n", err)
				os.Exit(1)
			}
			_, err = cmdBuild(context.Background(), opts, dockerOptions)
			if err != nil {
				cliLogger.Fatal(err)
			}
		},