-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathresource_test.go
58 lines (55 loc) · 1.96 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
46
47
48
49
50
51
52
53
54
55
56
57
58
package schema
import (
"testing"
"github.com/apache/arrow-go/v18/arrow"
"github.com/stretchr/testify/require"
)
func TestResource_Validate(t *testing.T) {
tests := []struct {
name string
resource *Resource
valueSetter func(resource *Resource) error
err error
}{
{
name: "valid resource without primary keys or primary key components",
resource: NewResourceData(&Table{Name: "test", Columns: ColumnList{{Name: "col1", Type: arrow.BinaryTypes.String}}}, nil, nil),
err: nil,
},
{
name: "valid resource with primary keys",
resource: NewResourceData(&Table{Name: "test", Columns: ColumnList{{Name: "col1", Type: arrow.BinaryTypes.String, PrimaryKey: true}}}, nil, nil),
err: nil,
valueSetter: func(resource *Resource) error {
return resource.Set("col1", "test")
},
},
{
name: "valid resource with primary key components",
resource: NewResourceData(&Table{Name: "test", Columns: ColumnList{{Name: "col1", Type: arrow.BinaryTypes.String, PrimaryKeyComponent: true}}}, nil, nil),
err: nil,
valueSetter: func(resource *Resource) error {
return resource.Set("col1", "test")
},
},
{
name: "invalid resource with primary keys",
resource: NewResourceData(&Table{Name: "test", Columns: ColumnList{{Name: "col1", Type: arrow.BinaryTypes.String, PrimaryKey: true}}}, nil, nil),
err: &PKError{MissingPKs: []string{"col1"}},
},
{
name: "invalid resource with primary key components",
resource: NewResourceData(&Table{Name: "test", Columns: ColumnList{{Name: "col1", Type: arrow.BinaryTypes.String, PrimaryKeyComponent: true}}}, nil, nil),
err: &PKComponentError{MissingPKComponents: []string{"col1"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.valueSetter != nil {
require.NoError(t, tt.valueSetter(tt.resource))
}
validationError := tt.resource.Validate()
require.Equal(t, tt.err, validationError)
})
}
}