mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-28 02:19:35 +00:00
* Use YAML group config to match machine labels to groups of zero or more machines sharing a Specification * Discontinue using machine.json resources representations which are repetitive, don't support groups, and don't allow label matching * Previous "default" special case now handled by a Group with an empty matcher
51 lines
1.3 KiB
Go
51 lines
1.3 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{
|
|
Groups: []Group{testGroup},
|
|
Specs: map[string]*Spec{testGroup.Spec: testSpec},
|
|
CloudConfigs: map[string]*CloudConfig{testSpec.CloudConfig: 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", "?uuid=a1b2c3d4", nil)
|
|
w := httptest.NewRecorder()
|
|
h.ServeHTTP(w, req)
|
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
|
}
|
|
|
|
func TestCloudHandler_MissingCloudConfig(t *testing.T) {
|
|
store := &fixedStore{
|
|
Groups: []Group{testGroup},
|
|
Specs: map[string]*Spec{testGroup.Spec: testSpec},
|
|
}
|
|
h := cloudHandler(store)
|
|
req, _ := http.NewRequest("GET", "?uuid=a1b2c3d4", nil)
|
|
w := httptest.NewRecorder()
|
|
h.ServeHTTP(w, req)
|
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
|
}
|