(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestAnalyze(t *testing.T) { |
| 11 | tt := []struct { |
| 12 | name string |
| 13 | template string |
| 14 | want *TemplateMetadata |
| 15 | wantErr error |
| 16 | }{ |
| 17 | { |
| 18 | name: "no template", |
| 19 | template: `SELECT * FROM foo`, |
| 20 | want: &TemplateMetadata{ |
| 21 | Variables: []string{}, |
| 22 | UsesTemplating: false, |
| 23 | ResolvedWithPlaceholders: `SELECT * FROM foo`, |
| 24 | }, |
| 25 | }, |
| 26 | { |
| 27 | name: "ref", |
| 28 | template: `SELECT * FROM {{ ref "foo" }}`, |
| 29 | want: &TemplateMetadata{ |
| 30 | Refs: []ResourceName{{Name: "foo"}}, |
| 31 | Variables: []string{}, |
| 32 | UsesTemplating: true, |
| 33 | ResolvedWithPlaceholders: `SELECT * FROM <no value>`, |
| 34 | }, |
| 35 | }, |
| 36 | { |
| 37 | name: "configure", |
| 38 | template: `{{ configure "a" "b" }}SELECT * FROM foo`, |
| 39 | want: &TemplateMetadata{ |
| 40 | Config: map[string]any{"a": "b"}, |
| 41 | Variables: []string{}, |
| 42 | UsesTemplating: true, |
| 43 | ResolvedWithPlaceholders: `SELECT * FROM foo`, |
| 44 | }, |
| 45 | }, |
| 46 | { |
| 47 | name: "complex", |
| 48 | template: `{{ configure "a: b\nc: d" }}{{ configure "e" "f" }}{{ dependency "bar" }} SELECT * FROM {{ ref "model" "foo" }} WHERE hello='{{ .env.world }}' AND world='{{ (lookup "baz").spec.baz.spaz }}'`, |
| 49 | want: &TemplateMetadata{ |
| 50 | Refs: []ResourceName{{Name: "bar"}, {Kind: ResourceKindModel, Name: "foo"}, {Name: "baz"}}, |
| 51 | Config: map[string]any{"a": "b", "c": "d", "e": "f"}, |
| 52 | Variables: []string{"env.world"}, |
| 53 | UsesTemplating: true, |
| 54 | ResolvedWithPlaceholders: `SELECT * FROM <no value> WHERE hello='<no value>' AND world='<no value>'`, |
| 55 | }, |
| 56 | }, |
| 57 | { |
| 58 | name: "variables", |
| 59 | template: `SELECT * FROM {{.env.partner_table_name}} WITH SAMPLING {{.env.partner_table_name}} .... {{.user.domain}}`, |
| 60 | want: &TemplateMetadata{ |
| 61 | Refs: []ResourceName{}, |
| 62 | Config: map[string]any{}, |
| 63 | Variables: []string{"env.partner_table_name", "user.domain"}, |
| 64 | UsesTemplating: true, |
| 65 | ResolvedWithPlaceholders: `SELECT * FROM <no value> WITH SAMPLING <no value> .... <no value>`, |
| 66 | }, |
| 67 | }, |
nothing calls this directly
no test coverage detected