-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathresource_test.go
45 lines (36 loc) · 1.01 KB
/
resource_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
// Package zebra_test tests structs and functions outlined in the zebra package.
package zebra_test
import (
"context"
"testing"
"github.com/project-safari/zebra"
"github.com/stretchr/testify/assert"
)
// TestBaseResource tests the *BaseResource Validate function with a pass case
// and a fail case.
func TestBaseResource(t *testing.T) {
t.Parallel()
assert := assert.New(t)
d, _ := dummyType()
ctx := context.Background()
res := &zebra.BaseResource{
Meta: zebra.NewMeta(d, "", "", ""),
Status: zebra.DefaultStatus(),
}
res.Meta.Name = ""
assert.NotNil(res.Validate(ctx))
res.Meta.ID = "abracadabra"
assert.NotNil(res.Validate(ctx))
assert.Equal("abracadabra", res.GetMeta().ID)
}
func TestGettingStatus(t *testing.T) {
t.Parallel()
assert := assert.New(t)
d, _ := dummyType()
ctx := context.Background()
res := zebra.NewBaseResource(d, "dummy", "dummy", "dummy")
assert.Nil(res.Validate(ctx))
assert.NotNil(res.GetStatus())
res.Status.Fault = zebra.Fault(100)
assert.NotNil(res.Validate(ctx))
}