Exemplo n.º 1
0
func TestFileConfig(t *testing.T) {
	assert := assert.New(t)

	file, err := ioutil.TempFile("", "tmp")
	assert.Nil(err)

	clearEnvVars()
	os.Setenv("CLC_ALIAS", "alias")
	os.Setenv("CLC_USER_AGENT", "some-sdk-client")
	conf, err := api.NewConfig("user", "pass")

	assert.Nil(err)
	b, _ := json.Marshal(conf)

	assert.Nil(ioutil.WriteFile(file.Name(), b, 755))

	c, err := api.FileConfig(file.Name())

	assert.Nil(err)
	assert.Equal("user", c.User.Username)
	assert.Equal("pass", c.User.Password)
	assert.Equal("alias", c.Alias)
	assert.Equal("some-sdk-client", c.UserAgent)

	file.Close()
	os.Remove(file.Name())
}
Exemplo n.º 2
0
func MaybeLoadConfig(c *cli.Context, client *clc.Client) (*clc.Client, error) {
	if c.GlobalString("config") != "" {
		config, err := api.FileConfig(c.GlobalString("config"))
		if err != nil {
			return nil, fmt.Errorf("failed to load config at %s", c.GlobalString("config"))
		}

		return clc.New(config), nil
	}

	return client, nil
}
Exemplo n.º 3
0
func loadClient() error {
	var config api.Config

	config, err := api.FileConfig("./config.json")
	if err != nil {
		config, err = api.EnvConfig()
		if err != nil {

			return err
		}
	}

	client = clc.New(config)
	return err
}
Exemplo n.º 4
0
func TestFileConfig(t *testing.T) {
	assert := assert.New(t)

	file, err := ioutil.TempFile("", "tmp")
	assert.Nil(err)

	conf, err := api.NewConfig("user", "pass", "alias", "https://api.ctl.io/v2")
	assert.Nil(err)
	b, _ := json.Marshal(conf)

	assert.Nil(ioutil.WriteFile(file.Name(), b, 755))

	c, err := api.FileConfig(file.Name())

	assert.Nil(err)
	assert.Equal("user", c.User.Username)
	assert.Equal("pass", c.User.Password)
	assert.Equal("alias", c.Alias)

	file.Close()
	os.Remove(file.Name())
}