github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/state/impl_response_storage_test.go (about) 1 /* 2 * Copyright (c) 2023-present unTill Pro, Ltd. 3 */ 4 5 package state 6 7 import ( 8 "context" 9 "testing" 10 11 "github.com/stretchr/testify/require" 12 13 "github.com/voedger/voedger/pkg/appdef" 14 "github.com/voedger/voedger/pkg/istructs" 15 ) 16 17 func TestResponseStorage(t *testing.T) { 18 var s IHostState 19 20 test := func(t *testing.T) { 21 kb, err := s.KeyBuilder(Response, appdef.NullQName) 22 require.NoError(t, err) 23 24 vb, err := s.NewValue(kb) 25 require.NoError(t, err) 26 27 vb.PutInt32(Field_StatusCode, 404) 28 vb.PutString(Field_ErrorMessage, "Not found") 29 30 kb2, err := s.KeyBuilder(Response, appdef.NullQName) 31 require.NoError(t, err) 32 intent := s.FindIntent(kb2) 33 require.NotNil(t, intent) 34 35 value := intent.BuildValue() 36 require.NotNil(t, value) 37 require.Equal(t, int32(404), value.AsInt32(Field_StatusCode)) 38 require.Equal(t, "Not found", value.AsString(Field_ErrorMessage)) 39 require.PanicsWithError(t, "unknown undefined", func() { 40 value.AsString("unknown") 41 }) 42 } 43 44 s = ProvideCommandProcessorStateFactory()(context.Background(), nil, nil, SimpleWSIDFunc(istructs.NullWSID), 45 nil, nil, nil, nil, 1, nil, nil, nil, nil) 46 t.Run("CommandProcessor", test) 47 s = ProvideQueryProcessorStateFactory()(context.Background(), nil, nil, SimpleWSIDFunc(istructs.NullWSID), 48 nil, nil, nil, nil, nil, nil, nil, nil) 49 t.Run("QueryProcessor", test) 50 51 }