github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/papi/response_link_test.go (about)

     1  package papi
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  	"github.com/tj/assert"
     8  )
     9  
    10  func TestResponseLinkParse(t *testing.T) {
    11  	tests := map[string]struct {
    12  		given     string
    13  		expected  string
    14  		withError bool
    15  	}{
    16  		"valid URL passed": {
    17  			given:    "/papi/v1/cpcodes/123?contractId=contract-1TJZFW&groupId=group",
    18  			expected: "123",
    19  		},
    20  		"invalid URL passed": {
    21  			given:     ":",
    22  			withError: true,
    23  		},
    24  	}
    25  	for name, test := range tests {
    26  		t.Run(name, func(t *testing.T) {
    27  			res, err := ResponseLinkParse(test.given)
    28  			if test.withError {
    29  				assert.Error(t, err)
    30  				return
    31  			}
    32  			require.NoError(t, err)
    33  			assert.Equal(t, test.expected, res)
    34  		})
    35  	}
    36  }