github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/soda/fizz/change_column_test.go (about) 1 package fizz 2 3 import "testing" 4 5 func Test_Change_Column(t *testing.T) { 6 cc := changeColumn{} 7 8 t.Run("no new column arg", func(t *testing.T) { 9 _, _, err := cc.GenerateFizz("change_companies_name", []string{}) 10 if err == nil { 11 t.Error("should error but got nil") 12 } 13 }) 14 15 t.Run("with new column arg", func(t *testing.T) { 16 up, down, err := cc.GenerateFizz("change_companies_price", []string{"float"}) 17 if err != nil { 18 t.Error("should not be nil but got err") 19 } 20 21 expectedUP := `change_column("companies", "price", "decimal", {})` 22 expectedDown := `change_column("companies", "price", "string", {})` 23 24 if up != expectedUP { 25 t.Errorf("expected %v but got %v", expectedUP, up) 26 } 27 28 if down != expectedDown { 29 t.Errorf("expected %v but got %v", expectedDown, down) 30 } 31 }) 32 33 t.Run("with new column null arg", func(t *testing.T) { 34 up, down, err := cc.GenerateFizz("change_companies_price", []string{"nulls.Int"}) 35 if err != nil { 36 t.Error("should not be nil but got err") 37 } 38 39 expectedUP := `change_column("companies", "price", "integer", {null: true})` 40 expectedDown := `change_column("companies", "price", "string", {})` 41 42 if up != expectedUP { 43 t.Errorf("expected %v but got %v", expectedUP, up) 44 } 45 46 if down != expectedDown { 47 t.Errorf("expected %v but got %v", expectedDown, down) 48 } 49 }) 50 } 51 52 func Test_Change_Column_Matches(t *testing.T) { 53 cc := changeColumn{} 54 55 cases := []struct { 56 name string 57 expected bool 58 }{ 59 {name: "change", expected: false}, 60 {name: "change_users", expected: false}, 61 {name: "change_companies_name", expected: true}, 62 } 63 64 for _, c := range cases { 65 matchs := cc.match(c.name) 66 if matchs != c.expected { 67 t.Errorf("expected %v but got %v", c.expected, matchs) 68 } 69 } 70 }