|
| 1 | +package python |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/bruin-data/bruin/pkg/pipeline" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestIsPythonMaterializationStrategySupported(t *testing.T) { |
| 11 | + t.Parallel() |
| 12 | + |
| 13 | + tests := []struct { |
| 14 | + name string |
| 15 | + strategy pipeline.MaterializationStrategy |
| 16 | + want bool |
| 17 | + }{ |
| 18 | + {name: "create+replace", strategy: pipeline.MaterializationStrategyCreateReplace, want: true}, |
| 19 | + {name: "append", strategy: pipeline.MaterializationStrategyAppend, want: true}, |
| 20 | + {name: "merge", strategy: pipeline.MaterializationStrategyMerge, want: true}, |
| 21 | + {name: "delete+insert", strategy: pipeline.MaterializationStrategyDeleteInsert, want: true}, |
| 22 | + {name: "time_interval", strategy: pipeline.MaterializationStrategyTimeInterval, want: true}, |
| 23 | + {name: "scd2_by_time is unsupported", strategy: pipeline.MaterializationStrategySCD2ByTime, want: false}, |
| 24 | + {name: "ddl is unsupported", strategy: pipeline.MaterializationStrategyDDL, want: false}, |
| 25 | + {name: "empty is unsupported", strategy: pipeline.MaterializationStrategyNone, want: false}, |
| 26 | + } |
| 27 | + |
| 28 | + for _, tt := range tests { |
| 29 | + t.Run(tt.name, func(t *testing.T) { |
| 30 | + t.Parallel() |
| 31 | + assert.Equal(t, tt.want, IsPythonMaterializationStrategySupported(tt.strategy)) |
| 32 | + }) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +func TestTranslateBruinStrategyToIngestr(t *testing.T) { |
| 37 | + t.Parallel() |
| 38 | + |
| 39 | + tests := []struct { |
| 40 | + name string |
| 41 | + strategy pipeline.MaterializationStrategy |
| 42 | + wantIngestr string |
| 43 | + wantExists bool |
| 44 | + }{ |
| 45 | + {name: "create+replace maps to replace", strategy: pipeline.MaterializationStrategyCreateReplace, wantIngestr: "replace", wantExists: true}, |
| 46 | + {name: "append maps to append", strategy: pipeline.MaterializationStrategyAppend, wantIngestr: "append", wantExists: true}, |
| 47 | + {name: "merge maps to merge", strategy: pipeline.MaterializationStrategyMerge, wantIngestr: "merge", wantExists: true}, |
| 48 | + {name: "delete+insert maps to delete+insert", strategy: pipeline.MaterializationStrategyDeleteInsert, wantIngestr: "delete+insert", wantExists: true}, |
| 49 | + {name: "time_interval maps to delete+insert", strategy: pipeline.MaterializationStrategyTimeInterval, wantIngestr: "delete+insert", wantExists: true}, |
| 50 | + {name: "unsupported strategy returns false", strategy: pipeline.MaterializationStrategySCD2ByTime, wantIngestr: "", wantExists: false}, |
| 51 | + } |
| 52 | + |
| 53 | + for _, tt := range tests { |
| 54 | + t.Run(tt.name, func(t *testing.T) { |
| 55 | + t.Parallel() |
| 56 | + got, exists := TranslateBruinStrategyToIngestr(tt.strategy) |
| 57 | + assert.Equal(t, tt.wantExists, exists) |
| 58 | + assert.Equal(t, tt.wantIngestr, got) |
| 59 | + }) |
| 60 | + } |
| 61 | +} |
0 commit comments