-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(WriteStagingModels): Add test to WriteStagingModels
Add an initial test that data is properly templated to staging models in WriteStagingModels.
- Loading branch information
1 parent
2bc0be5
commit 29b8fe8
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/gwenwindflower/tbd/shared" | ||
) | ||
|
||
func TestWriteStagingModels(t *testing.T) { | ||
ts := shared.SourceTables{ | ||
SourceTables: []shared.SourceTable{ | ||
{ | ||
Name: "table1", | ||
Columns: []shared.Column{ | ||
{ | ||
Name: "COLUMN3", | ||
DataType: "numbers", | ||
}, | ||
}, | ||
DataTypeGroups: map[string][]shared.Column{ | ||
"text": { | ||
shared.Column{ | ||
Name: "column1", | ||
DataType: "text", | ||
}, | ||
shared.Column{ | ||
Name: "column2", | ||
DataType: "text", | ||
}, | ||
}, | ||
"numbers": { | ||
shared.Column{ | ||
Name: "COLUMN3", | ||
DataType: "numbers", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
expect := `with | ||
source as ( | ||
select * from {{ ref('table1') }} | ||
), | ||
renamed as ( | ||
select | ||
-- numbers | ||
COLUMN3 as column3, | ||
-- text | ||
column1 as column1, | ||
column2 as column2, | ||
from source | ||
) | ||
select * from renamed | ||
` | ||
bd := t.TempDir() | ||
WriteStagingModels(ts, bd, "stg") | ||
got, err := os.ReadFile(bd + "/stg_table1.sql") | ||
if err != nil { | ||
t.Errorf("Error reading staging file %v", err) | ||
} | ||
if string(got) != expect { | ||
t.Errorf("Expected %v, got %v", expect, string(got)) | ||
} | ||
} |