Read user/pass from config and authenticate to OpenStack

This commit is contained in:
Angus Lees
2014-10-10 00:22:01 +11:00
parent 9bed117119
commit a90d503fce
2 changed files with 89 additions and 6 deletions

View File

@@ -22,8 +22,35 @@ import (
)
func TestNewOpenStack(t *testing.T) {
_, err := newOpenStack(strings.NewReader(""))
_, err := readConfig(nil)
if err == nil {
t.Errorf("Should fail when no config is provided: %s", err)
}
cfg, err := readConfig(strings.NewReader(`
[Global]
authurl = http://auth.url
username = user
`))
if err != nil {
t.Errorf("Should succeed when a valid config is provided: %s", err)
t.Fatalf("Should succeed when a valid config is provided: %s", err)
}
if cfg.Global.AuthUrl != "http://auth.url" {
t.Errorf("incorrect authurl: %s", cfg.Global.AuthUrl)
}
}
func TestToAuthOptions(t *testing.T) {
cfg := Config{}
cfg.Global.Username = "user"
// etc.
ao := cfg.toAuthOptions()
if !ao.AllowReauth {
t.Errorf("Will need to be able to reauthenticate")
}
if ao.Username != cfg.Global.Username {
t.Errorf("Username %s != %s", ao.Username, cfg.Global.Username)
}
}