github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/request/arguments_test.go (about)

     1  package request
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestArguments_InvalidParse(t *testing.T) {
    11  	var arguments Arguments
    12  
    13  	args := [][]string{
    14  		{"foo"},
    15  		{"-1"},
    16  		{"dGVzdA==", "foo"},
    17  	}
    18  
    19  	for _, a := range args {
    20  		err := arguments.Parse(a)
    21  		assert.EqualError(t, err, "invalid argument encoding: illegal base64 data at input byte 0", a)
    22  	}
    23  
    24  	tooLong := make([]string, maxAllowedScriptArguments+1)
    25  	for i := range tooLong {
    26  		tooLong[i] = "dGVzdA=="
    27  	}
    28  
    29  	err := arguments.Parse(tooLong)
    30  	assert.EqualError(t, err, fmt.Sprintf("too many arguments. Maximum arguments allowed: %d", maxAllowedScriptArguments))
    31  }
    32  
    33  func TestArguments_ValidParse(t *testing.T) {
    34  	var arguments Arguments
    35  
    36  	args := [][]string{
    37  		{"dGVzdA=="},
    38  		{},
    39  		{""},
    40  		{"dGVzdA==", "dGVzdCB0ZXN0IHRlc3QgMgo="},
    41  	}
    42  
    43  	for _, a := range args {
    44  		err := arguments.Parse(a)
    45  		assert.NoError(t, err)
    46  	}
    47  }