github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/query_test.go (about)

     1  package ccv3_test
     2  
     3  import (
     4  	"net/url"
     5  
     6  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("Query Helpers", func() {
    12  	Describe("FormatQueryParameters", func() {
    13  		var (
    14  			inputQueries     []Query
    15  			outputParameters url.Values
    16  		)
    17  
    18  		BeforeEach(func() {
    19  			inputQueries = []Query{
    20  				{
    21  					Key:    SpaceGUIDFilter,
    22  					Values: []string{"space-guid1", "space-guid2"},
    23  				},
    24  			}
    25  			outputParameters = FormatQueryParameters(inputQueries)
    26  		})
    27  
    28  		It("encodes the param values and reformats the query", func() {
    29  			Expect(outputParameters).To(Equal(url.Values{
    30  				"space_guids": []string{"space-guid1,space-guid2"},
    31  			}))
    32  		})
    33  
    34  		When("the name filter is used", func() {
    35  			BeforeEach(func() {
    36  				inputQueries = []Query{
    37  					{
    38  						Key:    NameFilter,
    39  						Values: []string{"name1", "name,2", "name 3"},
    40  					},
    41  				}
    42  				outputParameters = FormatQueryParameters(inputQueries)
    43  			})
    44  
    45  			It("encodes commas before formatting", func() {
    46  				Expect(outputParameters).To(Equal(url.Values{
    47  					"names": []string{"name1,name%2C2,name 3"},
    48  				}))
    49  			})
    50  		})
    51  	})
    52  })