github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/request/height_test.go (about) 1 package request 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestHeight_InvalidParse(t *testing.T) { 11 var height Height 12 13 tests := map[string]string{ 14 "f": "invalid height format", 15 "0xffffffffffffffff": "invalid height value", 16 "-1": "invalid height format", 17 fmt.Sprintf("%d", EmptyHeight): "invalid height value", 18 } 19 20 for in, outErr := range tests { 21 err := height.Parse(in) 22 assert.EqualError(t, err, outErr, fmt.Sprintf("test: value %s", in)) 23 } 24 } 25 26 func TestHeight_ValidParse(t *testing.T) { 27 tests := map[string]uint64{ 28 "1": uint64(1), 29 "": EmptyHeight, 30 "sealed": SealedHeight, 31 "final": FinalHeight, 32 } 33 34 var height Height 35 for in, out := range tests { 36 err := height.Parse(in) 37 assert.NoError(t, err) 38 assert.Equal(t, height.Flow(), out) 39 } 40 41 var heights Heights 42 err := heights.Parse([]string{"", "1", "2", "2", "2", ""}) 43 assert.NoError(t, err) 44 assert.Equal(t, len(heights.Flow()), 2) 45 assert.Equal(t, heights.Flow()[0], uint64(1)) 46 assert.Equal(t, heights.Flow()[1], uint64(2)) 47 }