github.com/xmidt-org/webpa-common@v1.11.9/secure/handler/context_test.go (about) 1 package handler 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestFromContextSatID(t *testing.T) { 11 t.Run("NoSatID", func(t *testing.T) { 12 assert := assert.New(t) 13 val, ofType := FromContext(context.Background()) 14 15 assert.False(ofType) 16 assert.Nil(val) 17 }) 18 19 t.Run("PresentSatID", func(t *testing.T) { 20 assert := assert.New(t) 21 inputCtxValues := &ContextValues{ 22 SatClientID: "test", 23 Path: "foo", 24 Method: "GET", 25 } 26 inputContext := context.WithValue(context.Background(), contextKey{}, inputCtxValues) 27 val, ofType := FromContext(inputContext) 28 29 assert.True(ofType) 30 assert.Equal(inputCtxValues, val) 31 }) 32 } 33 34 func TestNewContext(t *testing.T) { 35 assert := assert.New(t) 36 inputCtxValues := &ContextValues{ 37 SatClientID: "test", 38 Path: "foo", 39 Method: "GET", 40 } 41 expectedContext := context.WithValue(context.Background(), contextKey{}, inputCtxValues) 42 actualContext := NewContextWithValue(context.Background(), inputCtxValues) 43 44 assert.EqualValues(expectedContext, actualContext) 45 }