Merge pull request #197 from gottwald/testLoadAuthInfo

Add unit test for cloudcfg.LoadAuthInfo
pull/6/head
Daniel Smith 2014-06-21 08:33:12 -07:00
commit 25997dcfe2
1 changed files with 34 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
@ -292,6 +293,39 @@ func TestRequestWithBodyNoSuchFile(t *testing.T) {
}
}
func TestLoadAuthInfo(t *testing.T) {
testAuthInfo := &client.AuthInfo{
User: "TestUser",
Password: "TestPassword",
}
aifile, err := ioutil.TempFile("", "testAuthInfo")
if err != nil {
t.Error("Could not open temp file")
}
defer os.Remove(aifile.Name())
defer aifile.Close()
ai, err := LoadAuthInfo(aifile.Name())
if err == nil {
t.Error("LoadAuthInfo didn't fail on empty file")
}
data, err := json.Marshal(testAuthInfo)
if err != nil {
t.Fatal("Unexpected JSON marshal error")
}
_, err = aifile.Write(data)
if err != nil {
t.Fatal("Unexpected error in writing test file")
}
ai, err = LoadAuthInfo(aifile.Name())
if err != nil {
t.Fatal(err)
}
if *testAuthInfo != *ai {
t.Error("Test data and loaded data are not equal")
}
}
func TestRequestWithBody(t *testing.T) {
file, err := ioutil.TempFile("", "foo")
expectNoError(t, err)