-
Notifications
You must be signed in to change notification settings - Fork 4
/
optional_test.go
55 lines (47 loc) · 1.26 KB
/
optional_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
package api
import (
"testing"
core "github.com/hookdeck/hookdeck-go-sdk/core"
"github.com/stretchr/testify/assert"
)
func TestOptionalOrNull(t *testing.T) {
t.Run("nil primitive", func(t *testing.T) {
var value *string
optional := OptionalOrNull(value)
assert.Equal(t, &core.Optional[string]{Null: true}, optional)
})
t.Run("zero primitive", func(t *testing.T) {
var zero int
optional := OptionalOrNull(&zero)
assert.Equal(t, &core.Optional[int]{Value: zero}, optional)
})
t.Run("non-zero primitive", func(t *testing.T) {
value := "test"
optional := OptionalOrNull(&value)
assert.Equal(t, &core.Optional[string]{Value: value}, optional)
})
t.Run("nil type", func(t *testing.T) {
type foo struct {
Name string
}
var zero *foo
optional := OptionalOrNull(zero)
assert.Equal(t, &core.Optional[foo]{Null: true}, optional)
})
t.Run("zero type", func(t *testing.T) {
type foo struct {
Name string
}
zero := new(foo)
optional := OptionalOrNull(zero)
assert.Equal(t, &core.Optional[foo]{Value: *zero}, optional)
})
t.Run("non-zero type", func(t *testing.T) {
type foo struct {
Name string
}
value := &foo{Name: "test"}
optional := OptionalOrNull(value)
assert.Equal(t, &core.Optional[foo]{Value: *value}, optional)
})
}