Skip to content

Commit e08fc82

Browse files
authored
feat: allow model, application as asset type (#191)
1 parent 8833924 commit e08fc82

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

core/asset/type.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const (
66
TypeDashboard Type = "dashboard"
77
TypeTopic Type = "topic"
88
TypeFeatureTable Type = "feature_table"
9+
TypeApplication Type = "application"
10+
TypeModel Type = "model"
911
)
1012

1113
// AllSupportedTypes holds a list of all supported types struct
@@ -15,6 +17,8 @@ var AllSupportedTypes = []Type{
1517
TypeDashboard,
1618
TypeTopic,
1719
TypeFeatureTable,
20+
TypeApplication,
21+
TypeModel,
1822
}
1923

2024
// Type specifies a supported type name
@@ -28,7 +32,8 @@ func (t Type) String() string {
2832
// IsValid will validate whether the typename is valid or not
2933
func (t Type) IsValid() bool {
3034
switch t {
31-
case TypeTable, TypeJob, TypeDashboard, TypeTopic, TypeFeatureTable:
35+
case TypeTable, TypeJob, TypeDashboard, TypeTopic,
36+
TypeFeatureTable, TypeApplication, TypeModel:
3237
return true
3338
}
3439
return false

core/asset/type_test.go

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,37 @@
11
package asset
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
48

59
func TestTypeString(t *testing.T) {
6-
stringVal := TypeDashboard.String()
7-
if stringVal != "dashboard" {
8-
t.Fatalf("type dashboard converted to %s instead of 'dashboard'", stringVal)
9-
}
10-
stringVal = TypeJob.String()
11-
if stringVal != "job" {
12-
t.Fatalf("type job converted to %s instead of 'job'", stringVal)
13-
}
14-
stringVal = TypeTable.String()
15-
if stringVal != "table" {
16-
t.Fatalf("type table converted to %s instead of 'table'", stringVal)
17-
}
18-
stringVal = TypeTopic.String()
19-
if stringVal != "topic" {
20-
t.Fatalf("type topic converted to %s instead of 'topic'", stringVal)
10+
for typ, expected := range map[Type]string{
11+
TypeDashboard: "dashboard",
12+
TypeJob: "job",
13+
TypeTable: "table",
14+
TypeTopic: "topic",
15+
TypeFeatureTable: "feature_table",
16+
TypeApplication: "application",
17+
TypeModel: "model",
18+
} {
19+
t.Run((string)(typ), func(t *testing.T) {
20+
assert.Equal(t, expected, typ.String())
21+
})
2122
}
2223
}
2324

2425
func TestTypeIsValid(t *testing.T) {
25-
aType := Type("dashboard")
26-
if !aType.IsValid() {
27-
t.Fatalf("type %s is not valid", aType)
28-
}
29-
aType = Type("job")
30-
if !aType.IsValid() {
31-
t.Fatalf("type %s is not valid", aType)
32-
}
33-
aType = Type("table")
34-
if !aType.IsValid() {
35-
t.Fatalf("type %s is not valid", aType)
36-
}
37-
aType = Type("topic")
38-
if !aType.IsValid() {
39-
t.Fatalf("type %s is not valid", aType)
26+
for _, typ := range []Type{
27+
"dashboard", "job", "table", "topic", "feature_table", "application", "model",
28+
} {
29+
t.Run((string)(typ), func(t *testing.T) {
30+
assert.Truef(t, typ.IsValid(), "%s should be valid", typ)
31+
})
4032
}
4133

42-
aType = Type("random")
43-
if aType.IsValid() {
44-
t.Fatalf("type %s should not be valid", aType)
34+
if typ := Type("random"); typ.IsValid() {
35+
t.Fatalf("type %s should not be valid", typ)
4536
}
4637
}

internal/server/v1beta1/type_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ func TestGetTypes(t *testing.T) {
7878
Name: "feature_table",
7979
Count: 0,
8080
},
81+
{
82+
Name: "application",
83+
Count: 0,
84+
},
85+
{
86+
Name: "model",
87+
Count: 0,
88+
},
8189
},
8290
}
8391

0 commit comments

Comments
 (0)