2014-03-23 11:06:43 -07:00
|
|
|
package initialize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"testing"
|
2014-05-09 20:33:34 -07:00
|
|
|
|
|
|
|
"github.com/coreos/coreos-cloudinit/system"
|
2014-03-23 11:06:43 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestOEMReleaseWrittenToDisk(t *testing.T) {
|
|
|
|
oem := OEMRelease{
|
|
|
|
ID: "rackspace",
|
|
|
|
Name: "Rackspace Cloud Servers",
|
|
|
|
VersionID: "168.0.0",
|
|
|
|
HomeURL: "https://www.rackspace.com/cloud/servers/",
|
|
|
|
BugReportURL: "https://github.com/coreos/coreos-overlay",
|
|
|
|
}
|
|
|
|
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to create tempdir: %v", err)
|
|
|
|
}
|
2014-05-06 16:11:26 -07:00
|
|
|
defer os.RemoveAll(dir)
|
2014-03-23 11:06:43 -07:00
|
|
|
|
2014-05-09 20:33:34 -07:00
|
|
|
f, err := oem.File(dir)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Processing of OEMRelease failed: %v", err)
|
|
|
|
}
|
|
|
|
if f == nil {
|
|
|
|
t.Fatalf("OEMRelease returned nil file unexpectedly")
|
|
|
|
}
|
|
|
|
|
2014-06-05 12:48:32 -07:00
|
|
|
if _, err := system.WriteFile(f, dir); err != nil {
|
2014-05-09 20:33:34 -07:00
|
|
|
t.Fatalf("Writing of OEMRelease failed: %v", err)
|
2014-03-23 11:06:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fullPath := path.Join(dir, "etc", "oem-release")
|
|
|
|
|
|
|
|
fi, err := os.Stat(fullPath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to stat file: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if fi.Mode() != os.FileMode(0644) {
|
|
|
|
t.Errorf("File has incorrect mode: %v", fi.Mode())
|
|
|
|
}
|
|
|
|
|
|
|
|
contents, err := ioutil.ReadFile(fullPath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to read expected file: %v", err)
|
|
|
|
}
|
|
|
|
|
2014-04-07 09:56:57 -07:00
|
|
|
expect := `ID=rackspace
|
|
|
|
VERSION_ID=168.0.0
|
2014-03-23 11:06:43 -07:00
|
|
|
NAME="Rackspace Cloud Servers"
|
|
|
|
HOME_URL="https://www.rackspace.com/cloud/servers/"
|
|
|
|
BUG_REPORT_URL="https://github.com/coreos/coreos-overlay"
|
|
|
|
`
|
|
|
|
if string(contents) != expect {
|
|
|
|
t.Fatalf("File has incorrect contents")
|
|
|
|
}
|
|
|
|
}
|