Files
matchbox/api/cloud_test.go
Dalton Hubble bf72dde027 api: Convert handlers to ContextHandlers to isolate responsibility
* Add SpecMatcherHandler to match machine requests to Specs
2016-01-15 18:05:07 -08:00

44 lines
1.2 KiB
Go

package api
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestCloudHandler(t *testing.T) {
cloudcfg := &CloudConfig{Content: "#cloud-config"}
store := &fixedStore{
CloudConfigs: map[string]*CloudConfig{testSpec.CloudConfig: cloudcfg},
}
h := cloudHandler(store)
ctx := withSpec(context.Background(), testSpec)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
h.ServeHTTP(ctx, w, req)
// assert that:
// - the Spec's cloud config is served
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, cloudcfg.Content, w.Body.String())
}
func TestCloudHandler_MissingCtxSpec(t *testing.T) {
h := cloudHandler(&emptyStore{})
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
h.ServeHTTP(context.Background(), w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
}
func TestCloudHandler_MissingCloudConfig(t *testing.T) {
h := cloudHandler(&emptyStore{})
ctx := withSpec(context.Background(), testSpec)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
h.ServeHTTP(ctx, w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
}