github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/soda/fizz/drop_table_test.go (about) 1 package fizz 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func Test_Drop_Table(t *testing.T) { 9 ac := dropTable{} 10 t.Run("no table name", func(t *testing.T) { 11 _, _, err := ac.GenerateFizz("drop_table_", []string{}) 12 if err == nil { 13 t.Error("should error but got nil") 14 } 15 }) 16 17 t.Run("with table name", func(t *testing.T) { 18 up, down, err := ac.GenerateFizz("drop_table_users", []string{}) 19 if err != nil { 20 t.Error("should not be nil but got err") 21 } 22 23 expectedUP := `drop_table("users")` 24 expectedDown := `create_table("users")` 25 26 if up != expectedUP { 27 t.Errorf("expected %v but got %v", expectedUP, up) 28 } 29 30 if !strings.Contains(down, expectedDown) { 31 t.Errorf("expected %v but got %v", expectedDown, down) 32 } 33 }) 34 } 35 36 func Test_Drop_Table_Matches(t *testing.T) { 37 ac := dropTable{} 38 39 cases := []struct { 40 name string 41 expected bool 42 }{ 43 {name: "drop_table_", expected: true}, 44 {name: "drop_table", expected: false}, 45 {name: "drop_table_users", expected: true}, 46 } 47 48 for _, c := range cases { 49 matchs := ac.match(c.name) 50 if matchs != c.expected { 51 t.Errorf("expected %v but got %v", c.expected, matchs) 52 } 53 } 54 }