Files
matchbox/api/context_test.go
Dalton Hubble 76cec40b5a api: Add metadata endpoint with plain/text KEY=val's
* Show example with a custom metadata agent in Ignition
2016-01-31 01:13:53 -08:00

41 lines
952 B
Go

package api
import (
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestContextSpec(t *testing.T) {
expectedSpec := &Spec{ID: "g1h2i3j4"}
ctx := withSpec(context.Background(), expectedSpec)
spec, err := specFromContext(ctx)
assert.Nil(t, err)
assert.Equal(t, expectedSpec, spec)
}
func TestContextSpec_Error(t *testing.T) {
spec, err := specFromContext(context.Background())
assert.Nil(t, spec)
if assert.NotNil(t, err) {
assert.Equal(t, errNoSpecFromContext, err)
}
}
func TestGroupSpec(t *testing.T) {
expectedGroup := &Group{Name: "test group"}
ctx := withGroup(context.Background(), expectedGroup)
group, err := groupFromContext(ctx)
assert.Nil(t, err)
assert.Equal(t, expectedGroup, group)
}
func TestGroupSpec_Error(t *testing.T) {
group, err := groupFromContext(context.Background())
assert.Nil(t, group)
if assert.NotNil(t, err) {
assert.Equal(t, errNoGroupFromContext, err)
}
}