github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rest/request/id_test.go (about) 1 package request 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/onflow/flow-go/model/flow" 9 "github.com/onflow/flow-go/utils/unittest" 10 ) 11 12 func TestID_InvalidParse(t *testing.T) { 13 tests := map[string]string{ 14 "0x1": "invalid ID format", 15 "foo": "invalid ID format", 16 } 17 18 var id ID 19 for in, outErr := range tests { 20 err := id.Parse(in) 21 assert.EqualError(t, err, outErr) 22 } 23 } 24 25 func TestID_ValidParse(t *testing.T) { 26 testID := unittest.IdentifierFixture() 27 28 var id ID 29 err := id.Parse(testID.String()) 30 assert.NoError(t, err) 31 assert.Equal(t, id.Flow().String(), testID.String()) 32 33 err = id.Parse("") 34 assert.NoError(t, err) 35 assert.Equal(t, id.Flow().String(), flow.ZeroID.String()) 36 } 37 38 func TestIDs_ValidParse(t *testing.T) { 39 var testIDs []flow.Identifier = unittest.IdentifierListFixture(3) 40 41 var ids IDs 42 rawIDs := make([]string, 0) 43 for _, id := range testIDs { 44 rawIDs = append(rawIDs, id.String()) 45 } 46 47 err := ids.Parse(rawIDs) 48 assert.NoError(t, err) 49 assert.Equal(t, testIDs, ids.Flow()) 50 51 // duplication of ids 52 id := unittest.IdentifierFixture() 53 duplicatedIDs := []flow.Identifier{id, id, id} 54 rawIDs = make([]string, 0) 55 for _, id := range duplicatedIDs { 56 rawIDs = append(rawIDs, id.String()) 57 } 58 59 err = ids.Parse(rawIDs) 60 assert.NoError(t, err) 61 assert.Equal(t, 1, len(ids.Flow())) 62 assert.Equal(t, ids.Flow()[0], id) 63 } 64 65 func TestIDs_InvalidParse(t *testing.T) { 66 testIDs := make([]string, MaxIDsLength+1) 67 var ids IDs 68 err := ids.Parse(testIDs) 69 assert.EqualError(t, err, "at most 50 IDs can be requested at a time") 70 }