Example #1
0
func TestLoadAllCanReadProfiles(t *testing.T) {
	data := `
[profile flow]
docker_account = flowcommerce
docker_username = flow
docker_email = [email protected]
docker_password = dp
flow_user_token = fut
dependency_api_token = dat
travis_ci_api_token=tcat

[profile test]
docker_account = test
docker_username = test
docker_email = [email protected]
docker_password = dp2
flow_user_token = fut2
dependency_api_token = dat2
travis_ci_api_token=tcat2
`

	path := "/tmp/test.txt"
	err := ioutil.WriteFile(path, []byte(data), 0644)
	if err != nil {
		panic(err)
	}

	profiles, err := profile.LoadAll(path)
	if err != nil {
		panic(err)
	}

	if len(profiles) != 2 {
		t.Errorf("Expected 2 profiles but got %v", len(profiles))
	}

	expected := profile.Profile{
		Name:               "flow",
		FlowUserToken:      "fut",
		DockerAccount:      "flowcommerce",
		DockerUsername:     "******",
		DockerEmail:        "*****@*****.**",
		DockerPassword:     "******",
		DependencyApiToken: "dat",
		TravisCiApiToken:   "tcat",
	}
	if profiles[0] != expected {
		t.Errorf("Expected %+v but got  %+v", expected, profiles[0])
	}

	expected2 := profile.Profile{
		Name:               "test",
		FlowUserToken:      "fut2",
		DockerAccount:      "test",
		DockerUsername:     "******",
		DockerEmail:        "*****@*****.**",
		DockerPassword:     "******",
		DependencyApiToken: "dat2",
		TravisCiApiToken:   "tcat2",
	}
	if profiles[1] != expected2 {
		t.Errorf("Expected %+v but got  %+v", expected2, profiles[1])
	}

}
Example #2
0
func TestLoadAllWithInvalidPath(t *testing.T) {
	_, err := profile.LoadAll("/tmp/invalid.path.txt")
	if err == nil {
		t.Errorf("Expected error for non existent file but got nil")
	}
}