-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmap_key_conversion_test.go
More file actions
64 lines (55 loc) · 1.41 KB
/
Copy pathmap_key_conversion_test.go
File metadata and controls
64 lines (55 loc) · 1.41 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package sequencedmap
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// HTTPMethod mirrors the type from openapi package
type HTTPMethod string
const (
GET HTTPMethod = "get"
POST HTTPMethod = "post"
PUT HTTPMethod = "put"
DELETE HTTPMethod = "delete"
)
func TestNavigateWithKey_HTTPMethodConversion_Success(t *testing.T) {
t.Parallel()
tests := []struct {
name string
setupKey HTTPMethod
getKey string
expected string
}{
{
name: "HTTPMethod setup, string get",
setupKey: GET,
getKey: "get",
expected: "get_value",
},
{
name: "POST method",
setupKey: POST,
getKey: "post",
expected: "post_value",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
m := New[HTTPMethod, string]()
m.Set(tt.setupKey, tt.expected)
value, err := m.NavigateWithKey(tt.getKey)
require.NoError(t, err, "NavigateWithKey should not fail")
assert.Equal(t, tt.expected, value, "should return correct value")
})
}
}
func TestNavigateWithKey_InvalidKeyType_Error(t *testing.T) {
t.Parallel()
// Test with map that has non-string key type
m := New[int, string]()
m.Set(42, "value")
_, err := m.NavigateWithKey("42")
require.Error(t, err, "should fail with non-string key type")
assert.Contains(t, err.Error(), "key type must be string", "should contain appropriate error message")
}