-
Notifications
You must be signed in to change notification settings - Fork 6
/
common_test.go
66 lines (55 loc) · 1.42 KB
/
common_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
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package mql
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_panicIfNil(t *testing.T) {
t.Parallel()
assert.Panics(t, func() {
panicIfNil(nil, "test", "missing bit")
})
}
func Test_isNil(t *testing.T) {
t.Parallel()
var testErrNilPtr *testError
var testMapNilPtr map[string]struct{}
var testArrayNilPtr *[1]string
var testChanNilPtr *chan string
var testSliceNilPtr *[]string
var testFuncNil func()
var testChanString chan string
tc := []struct {
i any
want bool
}{
{i: &testError{}, want: false},
{i: testError{}, want: false},
{i: &map[string]struct{}{}, want: false},
{i: map[string]struct{}{}, want: false},
{i: [1]string{}, want: false},
{i: &[1]string{}, want: false},
{i: &testChanString, want: false},
{i: "string", want: false},
{i: []string{}, want: false},
{i: func() {}, want: false},
{i: nil, want: true},
{i: testErrNilPtr, want: true},
{i: testMapNilPtr, want: true},
{i: testArrayNilPtr, want: true},
{i: testChanNilPtr, want: true},
{i: testChanString, want: true},
{i: testSliceNilPtr, want: true},
{i: testFuncNil, want: true},
}
for i, tc := range tc {
t.Run(fmt.Sprintf("test #%d", i+1), func(t *testing.T) {
assert := assert.New(t)
assert.Equal(tc.want, isNil(tc.i))
})
}
}
type testError struct{}
func (*testError) Error() string { return "error" }