Files
matchbox/api/cloud_test.go
Dalton Hubble 72a782c4ef api: Use machine and spec resources to present cloud configs
* Change data/cloud directory to be a flat collection of cloud configs
2015-12-31 10:16:48 -08:00

49 lines
1.2 KiB
Go

package api
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCloudHandler(t *testing.T) {
cloudcfg := &CloudConfig{
Content: "#cloud-config",
}
store := &fixedStore{
Machines: map[string]*Machine{"a1b2c3d4": testMachine},
CloudConfigs: map[string]*CloudConfig{"cloud-config.yml": cloudcfg},
}
h := cloudHandler(store)
req, _ := http.NewRequest("GET", "?uuid=a1b2c3d4", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, req)
// assert that:
// - match parameters to a Spec
// - render the Spec's cloud config
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, cloudcfg.Content, w.Body.String())
}
func TestCloudHandler_NoMatchingSpec(t *testing.T) {
store := &emptyStore{}
h := cloudHandler(store)
req, _ := http.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
}
func TestCloudHandler_MissingCloudConfig(t *testing.T) {
store := &fixedStore{
Machines: map[string]*Machine{"a1b2c3d4": testMachine},
}
h := cloudHandler(store)
req, _ := http.NewRequest("GET", "?uuid=a1b2c3d4", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
}