-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils_test.go
54 lines (50 loc) · 1.08 KB
/
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
46
47
48
49
50
51
52
53
54
package template
import (
"testing"
"github.com/test-go/testify/assert"
)
func TestDereferenceIfNeeded(t *testing.T) {
// Define test cases
testCases := []struct {
name string
input interface{}
expectedNil bool // Expect the dereferenced value to be nil
}{
{
name: "Non-pointer string",
input: "test",
expectedNil: false,
},
{
name: "Pointer to string",
input: new(string),
expectedNil: false,
},
{
name: "Nil pointer to string",
input: (*string)(nil),
expectedNil: true,
},
{
name: "Non-pointer int",
input: 123,
expectedNil: false,
},
}
// Run test cases
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
derefed := dereferenceIfNeeded(tc.input)
if tc.expectedNil {
assert.Nil(t, derefed)
} else {
assert.NotNil(t, derefed)
// Additional type assertion if needed
if _, ok := tc.input.(*string); ok {
_, ok := derefed.(string)
assert.True(t, ok, "Expected a string type after dereferencing")
}
}
})
}
}