github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/soda/fizz/create_default_test.go (about)

     1  package fizz
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func Test_CreateDefault_Table(t *testing.T) {
     9  	ac := createDefault{}
    10  	t.Run("with name and no args", func(t *testing.T) {
    11  		up, down, err := ac.GenerateFizz("create_users", []string{})
    12  		if err != nil {
    13  			t.Error("should not be nil but got err")
    14  		}
    15  
    16  		upContains := []string{
    17  			"# You can add your migration from this point. For example:",
    18  			`# create_table("users") {`,
    19  			`#   t.Column("id", "uuid", {primary: true})`,
    20  			`#   t.Column("email", "string", {})`,
    21  		}
    22  
    23  		for _, c := range upContains {
    24  			if !strings.Contains(up, c) {
    25  				t.Errorf("expected %v but got %v", c, up)
    26  			}
    27  		}
    28  
    29  		downContains := []string{
    30  			"# You can add your migration from this point. For example:",
    31  			`# drop_table("users")`,
    32  		}
    33  
    34  		for _, c := range downContains {
    35  			if !strings.Contains(down, c) {
    36  				t.Errorf("expected %v but got %v", c, down)
    37  			}
    38  		}
    39  	})
    40  
    41  	t.Run("with name and args", func(t *testing.T) {
    42  		up, down, err := ac.GenerateFizz("create_users", []string{"email"})
    43  		if err != nil {
    44  			t.Error("should not be nil but got err")
    45  		}
    46  
    47  		upContains := []string{
    48  			"# You can add your migration from this point. For example:",
    49  			`# create_table("users") {`,
    50  			`#   t.Column("id", "uuid", {primary: true})`,
    51  			`#   t.Column("email", "string", {})`,
    52  		}
    53  
    54  		for _, c := range upContains {
    55  			if !strings.Contains(up, c) {
    56  				t.Errorf("expected %v but got %v", c, up)
    57  			}
    58  		}
    59  
    60  		downContains := []string{
    61  			"# You can add your migration from this point. For example:",
    62  			`# drop_table("users")`,
    63  		}
    64  
    65  		for _, c := range downContains {
    66  			if !strings.Contains(down, c) {
    67  				t.Errorf("expected %v but got %v", c, down)
    68  			}
    69  		}
    70  	})
    71  }