-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathclient_utils_test.go
45 lines (40 loc) · 1.16 KB
/
client_utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package utils
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
func TestAddQueryParams(t *testing.T) {
t.Run("NoQueryParams", func(t *testing.T) {
newurl, err := addQueryParams("https://avalabs.com", nil)
require.NoError(t, err)
require.Equal(t, "https://avalabs.com", newurl)
})
t.Run("TwoQueryParams", func(t *testing.T) {
newurl, err := addQueryParams("https://avalabs.com", map[string]string{
"first": "value1",
"second": "value2",
})
require.NoError(t, err)
require.Equal(t, "https://avalabs.com?first=value1&second=value2", newurl)
})
t.Run("InvalidEndpoint", func(t *testing.T) {
_, err := addQueryParams("invalid-endpoint", nil)
require.True(t, errors.Is(err, ErrInvalidEndpoint))
})
}
func TestNewClientOptions(t *testing.T) {
t.Run("NoHttpHeaders", func(t *testing.T) {
opts := newClientHeaderOptions(nil)
require.Len(t, opts, 0)
})
t.Run("TwoHttpHeaders", func(t *testing.T) {
opts := newClientHeaderOptions(map[string]string{
"first": "value1",
"second": "value2",
})
require.Len(t, opts, 2)
})
}