mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-27 18:19:36 +00:00
44 lines
1.2 KiB
Go
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)
|
|
}
|