Files
matchbox/bootcfg/api/context_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

42 lines
1.1 KiB
Go

package api
import (
"testing"
"github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestContextProfile(t *testing.T) {
expectedProfile := &storagepb.Profile{Id: "g1h2i3j4"}
ctx := withProfile(context.Background(), expectedProfile)
profile, err := profileFromContext(ctx)
assert.Nil(t, err)
assert.Equal(t, expectedProfile, profile)
}
func TestContextProfile_Error(t *testing.T) {
profile, err := profileFromContext(context.Background())
assert.Nil(t, profile)
if assert.NotNil(t, err) {
assert.Equal(t, errNoProfileFromContext, err)
}
}
func TestContextGroup(t *testing.T) {
expectedGroup := &storagepb.Group{Name: "test group"}
ctx := withGroup(context.Background(), expectedGroup)
group, err := groupFromContext(ctx)
assert.Nil(t, err)
assert.Equal(t, expectedGroup, group)
}
func TestContextGroup_Error(t *testing.T) {
group, err := groupFromContext(context.Background())
assert.Nil(t, group)
if assert.NotNil(t, err) {
assert.Equal(t, errNoGroupFromContext, err)
}
}