github.com/blend/go-sdk@v1.20220411.3/r2/opt_query_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package r2 9 10 import ( 11 "net/url" 12 "testing" 13 14 "github.com/blend/go-sdk/assert" 15 ) 16 17 func TestOptQuery(t *testing.T) { 18 assert := assert.New(t) 19 20 req := New(TestURL, 21 OptQuery(url.Values{ 22 "huff": []string{"buff"}, 23 "buzz": []string{"fuzz"}, 24 }), 25 ) 26 assert.NotNil(req.Request.URL) 27 assert.NotEmpty(req.Request.URL.RawQuery) 28 assert.NotEmpty(req.Request.URL.Query()) 29 assert.Equal("buff", req.Request.URL.Query().Get("huff")) 30 assert.Equal("fuzz", req.Request.URL.Query().Get("buzz")) 31 assert.Equal("buzz=fuzz&huff=buff", req.Request.URL.RawQuery) 32 } 33 34 func TestOptQueryValue(t *testing.T) { 35 assert := assert.New(t) 36 37 req := New(TestURL, 38 OptQueryValue("huff", "buff"), 39 OptQueryValue("buzz", "fuzz"), 40 ) 41 assert.NotNil(req.Request.URL) 42 assert.NotEmpty(req.Request.URL.RawQuery) 43 assert.NotEmpty(req.Request.URL.Query()) 44 assert.Equal("buff", req.Request.URL.Query().Get("huff")) 45 assert.Equal("fuzz", req.Request.URL.Query().Get("buzz")) 46 assert.Equal("buzz=fuzz&huff=buff&query=value", req.Request.URL.RawQuery) 47 } 48 49 func TestOptQueryValueAdd(t *testing.T) { 50 assert := assert.New(t) 51 52 req := New(TestURL, 53 OptQueryValue("huff", "buff"), 54 OptQueryValueAdd("huff", "fuzz"), 55 OptQueryValueAdd("foo", "bar"), 56 OptQueryValueAdd("foo", "baz"), 57 ) 58 assert.NotNil(req.Request.URL) 59 assert.NotEmpty(req.Request.URL.RawQuery) 60 assert.NotEmpty(req.Request.URL.Query()) 61 assert.Equal([]string{"buff", "fuzz"}, req.Request.URL.Query()["huff"]) 62 assert.Equal([]string{"bar", "baz"}, req.Request.URL.Query()["foo"]) 63 }