Beispiel #1
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)
}
Beispiel #2
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)
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #5
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)
}
Beispiel #6
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)
}
Beispiel #7
0
			}
			err = cmdVersion(opts)
			if err != nil {
				cliLogger.Fatal(err)
			}
		},
	}

	documentCommand = func(app *cli.App) cli.Command {
		return cli.Command{
			Name:  "doc",
			Usage: "Generate usage documentation",
			Action: func(c *cli.Context) {
				settings := util.NewCLISettings(c)
				env := util.NewEnvironment(os.Environ()...)
				opts, err := core.NewGlobalOptions(settings, env)
				if err != nil {
					cliLogger.Errorln("Invalid options\n", err)
					os.Exit(1)
				}
				if err := GenerateDocumentation(opts, app); err != nil {
					cliLogger.Fatal(err)
				}
			},
		}
	}
)

func GetApp() *cli.App {
	// logger.SetLevel(logger.DebugLevel)
	// util.RootLogger().SetLevel("debug")