|
1 | 1 | package asset |
2 | 2 |
|
3 | | -import "testing" |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
4 | 8 |
|
5 | 9 | 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 | + }) |
21 | 22 | } |
22 | 23 | } |
23 | 24 |
|
24 | 25 | 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 | + }) |
40 | 32 | } |
41 | 33 |
|
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) |
45 | 36 | } |
46 | 37 | } |
0 commit comments