Files
matchbox/bootcfg/api/cloud_test.go
Dalton Hubble 300291780e tests: Fix marshal/unmarhal errors for Groups without metadata
* Expand the use of testfakes to decrease test fixture duplication
* Add test coverage for numbers and booleans in Group metadata
2016-04-05 17:14:38 -07:00

52 lines
1.6 KiB
Go

package api
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
"github.com/coreos/coreos-baremetal/bootcfg/server"
"github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb"
fake "github.com/coreos/coreos-baremetal/bootcfg/storage/testfakes"
)
func TestCloudHandler(t *testing.T) {
content := "#cloud-config"
store := &fake.FixedStore{
Profiles: map[string]*storagepb.Profile{fake.Group.Profile: fake.Profile},
CloudConfigs: map[string]string{fake.Profile.CloudId: content},
}
srv := server.NewServer(&server.Config{Store: store})
h := cloudHandler(srv)
ctx := withGroup(context.Background(), fake.Group)
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) {
srv := server.NewServer(&server.Config{Store: &fake.EmptyStore{}})
h := cloudHandler(srv)
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) {
srv := server.NewServer(&server.Config{Store: &fake.EmptyStore{}})
h := cloudHandler(srv)
ctx := withProfile(context.Background(), fake.Profile)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
h.ServeHTTP(ctx, w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
}