func TestStepInjectConfiguration(t *testing.T) {
	env := new(multistep.BasicStateBag)
	os.Mkdir("tmp", 0777)
	env.Put("config_path", "tmp/")

	conf := config.NewDefault()

	// Create the configuration file sections and items
	conf.AddSection("gethub")
	conf.AddSection("github")
	conf.AddSection("ignores")
	conf.AddOption("gethub", "path", "tmp")
	conf.AddOption("github", "username", "foo")
	conf.AddOption("github", "token", "bar")
	conf.AddOption("ignores", "repo", "facebook")
	conf.AddOption("ignores", "owner", "pearkes")

	conf.WriteFile("tmp/.gethubconfig", 0644, "")

	step := &StepInjectConfiguration{}

	results := step.Run(env)

	if results != multistep.ActionContinue {
		t.Fatal("step did not return ActionContinue")
	}

	os.RemoveAll("tmp")
}
예제 #2
0
func (*StepCreateConfiguration) Run(state multistep.StateBag) multistep.StepAction {
	log.Println("Creating configuration...")

	path := state.Get("path").(string)
	username := state.Get("username").(string)
	token := state.Get("token").(string)
	host := state.Get("host").(string)

	conf := config.NewDefault()

	// Create the configuration file sections and items
	conf.AddSection("gethub")
	conf.AddSection("github")
	conf.AddSection("ignores")
	conf.AddOption("gethub", "path", path)
	conf.AddOption("github", "username", username)
	conf.AddOption("github", "token", token)
	conf.AddOption("github", "host", host)
	conf.AddOption("ignores", "repo", "")
	conf.AddOption("ignores", "owner", "")

	conf.WriteFile(os.Getenv("HOME")+"/.gethubconfig", 0644, "")

	return multistep.ActionContinue
}
예제 #3
0
func createTestConfig() *config.Config {
	os.Mkdir("tmp", 0777)
	c := config.NewDefault()
	c.AddSection("settings")
	c.AddOption("settings", "token", "1329gj328v2n9bu2")
	c.AddOption("settings", "email", "*****@*****.**")
	c.AddOption("settings", "source", "test")
	c.AddOption("settings", "url", "localhost:8000/nginx_status")
	c.AddOption("settings", "flush_interval", "1s")
	return c
}