github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/ox/resource/generator_test.go (about)

     1  package resource
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  )
     9  
    10  func Test_Generate(t *testing.T) {
    11  	g := Generator{}
    12  	dir := t.TempDir()
    13  
    14  	// Creating folders before hand
    15  	folders := []string{"app/actions", "app/models", "app/templates", "migrations"}
    16  	for _, f := range folders {
    17  		actionsPath := filepath.Join(dir, f)
    18  		if err := os.MkdirAll(actionsPath, os.ModePerm); err != nil {
    19  			t.Errorf("creating %s folder should not be error, but got %v", f, err)
    20  		}
    21  	}
    22  
    23  	if err := g.Generate(context.Background(), dir, []string{"generate", "resource", "animals", "age:int", "breed", "nationality"}); err != nil {
    24  		t.Errorf("should not be error, but got %v", err)
    25  	}
    26  
    27  	// Validating Files existence
    28  	files := []string{
    29  		"app/actions/animals.go",
    30  		"app/actions/animals_test.go",
    31  		"app/models/animal.go",
    32  		"app/models/animal_test.go",
    33  		"app/templates/animals/index.plush.html",
    34  		"app/templates/animals/new.plush.html",
    35  		"app/templates/animals/edit.plush.html",
    36  		"app/templates/animals/show.plush.html",
    37  		"app/templates/animals/form.plush.html",
    38  	}
    39  
    40  	for _, f := range files {
    41  		path := filepath.Join(dir, f)
    42  		if _, err := os.Stat(path); os.IsNotExist(err) {
    43  			t.Errorf("'%s' file does not exists on the path", path)
    44  		}
    45  	}
    46  }