github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/services/marketplace/client_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package marketplace 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestBuildURL(t *testing.T) { 13 config := &Client{} 14 15 testCases := map[string]struct { 16 base string 17 path string 18 expected string 19 }{ 20 "Base url with trailing slash and path with leading slash": { 21 base: "https://api.integrations.mattermost.com/", 22 path: "/api/v1/plugins", 23 expected: "https://api.integrations.mattermost.com/api/v1/plugins", 24 }, 25 "Base url without trailing slash and path with leading slash": { 26 base: "https://api.integrations.mattermost.com", 27 path: "/api/v1/plugins", 28 expected: "https://api.integrations.mattermost.com/api/v1/plugins", 29 }, 30 "Base url without trailing slash and path without leading slash": { 31 base: "https://api.integrations.mattermost.com", 32 path: "api/v1/plugins", 33 expected: "https://api.integrations.mattermost.com/api/v1/plugins", 34 }, 35 } 36 37 for name, tt := range testCases { 38 t.Run(name, func(t *testing.T) { 39 config.address = tt.base 40 actual := config.buildURL(tt.path) 41 assert.Equal(t, tt.expected, actual) 42 }) 43 } 44 }