Skip to content

Commit

Permalink
test(WriteStagingModels): Add test to WriteStagingModels
Browse files Browse the repository at this point in the history
Add an initial test that data is properly templated to staging models in WriteStagingModels.
  • Loading branch information
gwenwindflower committed Apr 17, 2024
1 parent 2bc0be5 commit 29b8fe8
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions write_staging_models_test.go
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))
}
}

0 comments on commit 29b8fe8

Please sign in to comment.