Files
matchbox/api/http_test.go
Dalton Hubble ccd3c7a839 api: Associate machines' attribute labels to specs by group matchers
* 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
2016-01-07 23:24:05 -08:00

33 lines
1.1 KiB
Go

package api
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLabelsFromRequest(t *testing.T) {
emptyMap := map[string]string{}
cases := []struct {
urlString string
labelSet map[string]string
}{
{"http://a.io", emptyMap},
{"http://a.io?uuid=a1b2c3", map[string]string{"uuid": "a1b2c3"}},
{"http://a.io?uuid=a1b2c3", map[string]string{"uuid": "a1b2c3"}},
{"http://a.io?mac=52:54:00:89:d8:10", map[string]string{"mac": validMACStr}},
{"http://a.io?mac=52-54-00-89-d8-10", map[string]string{"mac": validMACStr}},
{"http://a.io?uuid=a1b2c3&mac=52:54:00:89:d8:10", map[string]string{"uuid": "a1b2c3", "mac": validMACStr}},
// parse and set MAC regardless of query argument case
{"http://a.io?UUID=a1b2c3&MAC=52:54:00:89:d8:10", map[string]string{"UUID": "a1b2c3", "MAC": validMACStr}},
// ignore MAC addresses which do not parse
{"http://a.io?mac=?:?:?", emptyMap},
}
for _, c := range cases {
req, err := http.NewRequest("GET", c.urlString, nil)
assert.Nil(t, err)
assert.Equal(t, LabelSet(c.labelSet), labelsFromRequest(req))
}
}