github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/request/get_events_test.go (about) 1 package request 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestGetEvents_InvalidParse(t *testing.T) { 11 var getEvents GetEvents 12 13 tests := []struct { 14 eventType string 15 start string 16 end string 17 ids []string 18 err string 19 }{ 20 {"flow.AccountCreated", "", "", nil, "must provide either block IDs or start and end height range"}, 21 {"flow.AccountCreated", "10", "", nil, "must provide either block IDs or start and end height range"}, 22 {"flow.AccountCreated", "", "10", nil, "must provide either block IDs or start and end height range"}, 23 {"flow.AccountCreated", "5", "10", []string{"7bc42fe85d32ca513769a74f97f7e1a7bad6c9407f0d934c2aa645ef9cf613c7"}, "can only provide either block IDs or start and end height range"}, 24 {"foo", "5", "10", nil, "invalid event type format"}, 25 {"A.123.Foo.Bar", "5", "10", nil, "invalid event type format"}, 26 {"A.f8d6e0586b0a20c7.Foo.Bar", "20", "10", nil, "start height must be less than or equal to end height"}, 27 {"A.f8d6e0586b0a20c7.Foo.Bar", "0", "500", nil, "height range 500 exceeds maximum allowed of 250"}, 28 {"A.f8d6e0586b0a20c7.Foo.Bar", "0", "", make([]string, 100), "at most 50 IDs can be requested at a time"}, 29 } 30 31 for i, test := range tests { 32 err := getEvents.Parse(test.eventType, test.start, test.end, test.ids) 33 assert.EqualError(t, err, test.err, fmt.Sprintf("test #%d failed", i)) 34 } 35 } 36 37 func TestGetEvents_ValidParse(t *testing.T) { 38 var getEvents GetEvents 39 40 event := "A.f8d6e0586b0a20c7.Foo.Bar" 41 err := getEvents.Parse(event, "5", "10", nil) 42 assert.NoError(t, err) 43 assert.Equal(t, getEvents.Type, event) 44 assert.Equal(t, getEvents.StartHeight, uint64(5)) 45 assert.Equal(t, getEvents.EndHeight, uint64(10)) 46 assert.Equal(t, len(getEvents.BlockIDs), 0) 47 48 event = "flow.AccountCreated" 49 err = getEvents.Parse(event, "", "", []string{ 50 "7bc42fe85d32ca513769a74f97f7e1a7bad6c9407f0d934c2aa645ef9cf613c7", 51 "7bc42fe85d32ca513769a74f97f7e1a7bad6c9407f0d934c2aa645ef9cf613c7", // intentional duplication 52 "2ab81061b12d95fb81f2923001e340bc808e67e1eaae3c62479057cc14eb57fd", 53 }) 54 assert.NoError(t, err) 55 assert.Equal(t, getEvents.Type, event) 56 assert.Equal(t, getEvents.StartHeight, EmptyHeight) 57 assert.Equal(t, getEvents.EndHeight, EmptyHeight) 58 assert.Equal(t, len(getEvents.BlockIDs), 2) 59 assert.Equal(t, getEvents.BlockIDs[0].String(), "7bc42fe85d32ca513769a74f97f7e1a7bad6c9407f0d934c2aa645ef9cf613c7") 60 assert.Equal(t, getEvents.BlockIDs[1].String(), "2ab81061b12d95fb81f2923001e340bc808e67e1eaae3c62479057cc14eb57fd") 61 62 }