|
1 | 1 | package loadjson |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "embed" |
4 | 5 | _ "embed" |
5 | 6 | "encoding/json" |
6 | 7 | "github.com/stretchr/testify/assert" |
7 | 8 | "pbench/presto/query_json" |
8 | 9 | "testing" |
9 | 10 | ) |
10 | 11 |
|
11 | | -//go:embed 20240422_013209_00111_k6ve9_shows_schema.json |
12 | | -var testJson []byte |
| 12 | +// Embed multiple JSON files |
| 13 | +// |
| 14 | +//go:embed *.json |
| 15 | +var testFiles embed.FS |
| 16 | + |
| 17 | +type testCase struct { |
| 18 | + name string |
| 19 | + filePath string |
| 20 | + expected int |
| 21 | +} |
13 | 22 |
|
14 | 23 | func TestParseQueryInfo(t *testing.T) { |
15 | | - queryInfo := new(query_json.QueryInfo) |
16 | | - assert.Nil(t, json.Unmarshal(testJson, queryInfo)) |
17 | | - assert.Nil(t, queryInfo.PrepareForInsert()) |
18 | | - assert.Nil(t, queryInfo.OutputStage) |
19 | | - assert.Equal(t, 4, len(queryInfo.FlattenedStageList)) |
| 24 | + tests := []testCase{ |
| 25 | + { |
| 26 | + name: "Presto query info JSON", |
| 27 | + filePath: "20240422_013209_00111_k6ve9_shows_schema.json", |
| 28 | + expected: 4, |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "Trino query info JSON", |
| 32 | + filePath: "trino_query_info.json", |
| 33 | + expected: 5, |
| 34 | + }, |
| 35 | + // Add more test cases as needed |
| 36 | + } |
| 37 | + |
| 38 | + for _, tc := range tests { |
| 39 | + t.Run(tc.name, func(t *testing.T) { |
| 40 | + jsonBytes, err := testFiles.ReadFile(tc.filePath) |
| 41 | + assert.Nil(t, err) |
| 42 | + |
| 43 | + queryInfo := new(query_json.QueryInfo) |
| 44 | + assert.Nil(t, json.Unmarshal(jsonBytes, queryInfo)) |
| 45 | + assert.Nil(t, queryInfo.PrepareForInsert()) |
| 46 | + assert.Nil(t, queryInfo.OutputStage) |
| 47 | + assert.Equal(t, tc.expected, len(queryInfo.FlattenedStageList)) |
| 48 | + }) |
| 49 | + } |
20 | 50 | } |
0 commit comments