Add test for validation

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
Nathan LeClaire 2015-03-20 21:46:27 -07:00
parent d91d777f6e
commit 04f5679e4f
1 changed files with 29 additions and 0 deletions

View File

@ -1,5 +1,34 @@
package libmachine
import (
"os"
"reflect"
"testing"
)
// Tests a function which "prefills" certificate information for a host
// due to a schema migration from "flat" to a "nested" structure.
func TestGetCertInfoFromHost(t *testing.T) {
os.Setenv("MACHINE_STORAGE_PATH", "/tmp/migration")
host := &Host{
CaCertPath: "",
PrivateKeyPath: "",
ClientCertPath: "",
ClientKeyPath: "",
ServerCertPath: "",
ServerKeyPath: "",
}
expectedCertInfo := CertPathInfo{
CaCertPath: "/tmp/migration/certs/ca.pem",
CaKeyPath: "/tmp/migration/certs/ca-key.pem",
ClientCertPath: "/tmp/migration/certs/cert.pem",
ClientKeyPath: "/tmp/migration/certs/key.pem",
ServerCertPath: "/tmp/migration/certs/server.pem",
ServerKeyPath: "/tmp/migration/certs/server-key.pem",
}
certInfo := getCertInfoFromHost(host)
if !reflect.DeepEqual(expectedCertInfo, certInfo) {
t.Log("\n\n\n", expectedCertInfo, "\n\n\n", certInfo)
t.Fatal("Expected these structs to be equal, they were different")
}
}