-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtable_options_test.go
More file actions
62 lines (57 loc) · 1.73 KB
/
table_options_test.go
File metadata and controls
62 lines (57 loc) · 1.73 KB
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
package docs
import (
_ "embed"
"github.com/cloudquery/plugin-sdk/v4/docs/testdata"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/stretchr/testify/require"
"testing"
)
//go:embed testdata/schema.json
var testSchema string
type testTableOptions struct {
Dummy testdata.DummyTableOptions `json:"dummy,omitempty"`
}
var testTable = &schema.Table{
Name: "dummy",
Description: "This is a dummy table",
}
func TestTableOptionsDescriptionTransformer(t *testing.T) {
type args struct {
tableOptions any
jsonSchema string
table *schema.Table
}
tests := []struct {
name string
args args
wantDesc string
wantErr bool
}{
{
name: "adds table options to description",
args: args{tableOptions: &testTableOptions{}, jsonSchema: testSchema, table: testTable},
wantDesc: "This is a dummy table\n\n## <a name=\"Table Options\"></a>Table Options\n\n DummyTableOptions contains configuration for the dummy table\n\n* `filter` (`string`)\n",
},
{
name: "leaves description unchanged when table doesn't have options",
args: args{tableOptions: &testTableOptions{}, jsonSchema: testSchema, table: &schema.Table{Description: "Foobar"}},
wantDesc: "Foobar",
},
{
name: "errors out when table options don't match schema",
wantErr: true,
args: args{tableOptions: &testTableOptions{}, jsonSchema: "", table: testTable},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
transformer, err := TableOptionsDescriptionTransformer(tt.args.tableOptions, tt.args.jsonSchema)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, transformer(tt.args.table))
require.Equal(t, tt.wantDesc, tt.args.table.Description)
})
}
}