github.com/wawandco/oxplugins@v0.7.11/tools/pop/migration/creator/fizz_creator_test.go (about)

     1  package creator
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func Test_Fizz_Create(t *testing.T) {
    10  	f := FizzCreator{}
    11  
    12  	t.Run("generate migration files", func(t *testing.T) {
    13  		dir := t.TempDir()
    14  		args := []string{"users"}
    15  
    16  		if err := f.Create(dir, args); err != nil {
    17  			t.Errorf("creating migration files should not be error, but got %v", err)
    18  		}
    19  
    20  		// Validating files existence
    21  		match, err := filepath.Glob(filepath.Join(dir, "*users.*.fizz"))
    22  		if err != nil {
    23  			t.Errorf("searching for files should not error, but got %v", err)
    24  		}
    25  
    26  		if len(match) == 0 {
    27  			t.Error("migration files does not exists on the path")
    28  		}
    29  
    30  		if !strings.HasSuffix(match[0], "_users.down.fizz") {
    31  			t.Error("'users.up.fizz' file does not exists on the path")
    32  		}
    33  
    34  		if !strings.HasSuffix(match[1], "_users.up.fizz") {
    35  			t.Error("'users.down.fizz' file does not exists on the path")
    36  		}
    37  	})
    38  
    39  	t.Run("generate migration singularized name", func(t *testing.T) {
    40  		dir := t.TempDir()
    41  		args := []string{"company"}
    42  
    43  		if err := f.Create(dir, args); err != nil {
    44  			t.Errorf("creating migration files should not be error, but got %v", err)
    45  		}
    46  
    47  		// Validating files existence
    48  		match, err := filepath.Glob(filepath.Join(dir, "*companies.*.fizz"))
    49  		if err != nil {
    50  			t.Errorf("searching for files should not error, but got %v", err)
    51  		}
    52  
    53  		if len(match) == 0 {
    54  			t.Error("migration files does not exists on the path")
    55  		}
    56  
    57  		if !strings.HasSuffix(match[0], "_companies.down.fizz") {
    58  			t.Error("'companies.up.fizz' file does not exists on the path")
    59  		}
    60  
    61  		if !strings.HasSuffix(match[1], "_companies.up.fizz") {
    62  			t.Error("'companies.down.fizz' file does not exists on the path")
    63  		}
    64  	})
    65  }