From 29b8fe86f4d92c0a7acb3c4f82feefc8c9a68fcf Mon Sep 17 00:00:00 2001 From: gwen windflower Date: Tue, 16 Apr 2024 19:08:16 -0500 Subject: [PATCH] test(WriteStagingModels): Add test to WriteStagingModels Add an initial test that data is properly templated to staging models in WriteStagingModels. --- write_staging_models_test.go | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 write_staging_models_test.go diff --git a/write_staging_models_test.go b/write_staging_models_test.go new file mode 100644 index 0000000..6f9b2f1 --- /dev/null +++ b/write_staging_models_test.go @@ -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)) + } +}