github.com/SigNoz/golang-migrate/v4@v4.0.0-20231005133642-7493dbaf5f5b/template_test.go (about) 1 package migrate 2 3 import ( 4 "bytes" 5 "io" 6 "os" 7 "testing" 8 ) 9 10 func Test_applyEnvironmentTemplate(t *testing.T) { 11 envMapCache = nil 12 _ = os.Setenv("WAREHOUSE_DB", "WH_STAGING") 13 14 migration := io.NopCloser(bytes.NewBuffer([]byte(`SELECT * FROM {{.WAREHOUSE_DB}}.STD.INVOICES`))) 15 16 gotReader, err := applyEnvironmentTemplate(migration) 17 if err != nil { 18 t.Fatalf("expected no error applying template") 19 } 20 21 gotBytes, err := io.ReadAll(gotReader) 22 if err != nil { 23 t.Fatalf("expected no error reading") 24 } 25 got := string(gotBytes) 26 want := `SELECT * FROM WH_STAGING.STD.INVOICES` 27 if got != want { 28 t.Fatalf("expected [%s] but got [%s]", want, got) 29 } 30 }