Files
matchbox/bootcfg/api/cloud_test.go
Dalton Hubble 0d148581b9 bootcfg/api: Switch from api types to storagepb types
* Remove api.Store and use storagepb.Store instead
* Remove api.Spec and use storagepb.Profile instead
* Switch from api.Group to storagepb.Group
* Move api.Group to config for YAML config decoding only
2016-03-10 18:32:57 -08:00

46 lines
1.3 KiB
Go

package api
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestCloudHandler(t *testing.T) {
content := "#cloud-config"
store := &fixedStore{
Profiles: map[string]*storagepb.Profile{testGroup.Profile: testProfile},
CloudConfigs: map[string]string{testProfile.CloudId: content},
}
h := cloudHandler(store)
ctx := withGroup(context.Background(), testGroup)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
h.ServeHTTP(ctx, w, req)
// assert that:
// - Cloud config is rendered with Group metadata
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, content, w.Body.String())
}
func TestCloudHandler_MissingCtxProfile(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 := withProfile(context.Background(), testProfile)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
h.ServeHTTP(ctx, w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
}