github.com/gofiber/fiber-cli@v0.0.3/cmd/new_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func Test_New_Run(t *testing.T) {
    11  	at := assert.New(t)
    12  
    13  	t.Run("new project", func(t *testing.T) {
    14  		defer func() {
    15  			at.Nil(os.Chdir("../"))
    16  			_ = os.RemoveAll("normal")
    17  		}()
    18  
    19  		setupCmd()
    20  		defer teardownCmd()
    21  
    22  		out, err := runCobraCmd(newCmd, "normal")
    23  
    24  		at.Nil(err)
    25  		at.Contains(out, "Done")
    26  	})
    27  
    28  	t.Run("custom mod name", func(t *testing.T) {
    29  		defer func() {
    30  			at.Nil(os.Chdir("../"))
    31  			at.Nil(os.RemoveAll("custom_mod_name"))
    32  		}()
    33  
    34  		setupCmd()
    35  		defer teardownCmd()
    36  
    37  		out, err := runCobraCmd(newCmd, "custom_mod_name", "name")
    38  
    39  		at.Nil(err)
    40  		at.Contains(out, "name")
    41  	})
    42  
    43  	t.Run("create complex project", func(t *testing.T) {
    44  		defer func() {
    45  			at.Nil(os.Chdir("../"))
    46  			at.Nil(os.RemoveAll("complex"))
    47  		}()
    48  
    49  		setupCmd()
    50  		defer teardownCmd()
    51  
    52  		out, err := runCobraCmd(newCmd, "complex", "-t=complex")
    53  		at.Nil(err)
    54  		at.Contains(out, "Done")
    55  	})
    56  
    57  	t.Run("failed to create complex project", func(t *testing.T) {
    58  		defer func() {
    59  			at.Nil(os.Chdir("../"))
    60  			at.Nil(os.RemoveAll("complex_failed"))
    61  		}()
    62  
    63  		setupCmd(errFlag)
    64  		defer teardownCmd()
    65  
    66  		out, err := runCobraCmd(newCmd, "complex_failed", "-t=complex")
    67  
    68  		at.NotNil(err)
    69  		at.Contains(out, "failed to run")
    70  	})
    71  
    72  	t.Run("invalid project name", func(t *testing.T) {
    73  		out, err := runCobraCmd(newCmd, ".")
    74  
    75  		at.NotNil(err)
    76  		at.Contains(out, ".")
    77  	})
    78  }
    79  
    80  func Test_New_CreateBasic(t *testing.T) {
    81  	assert.NotNil(t, createBasic(" ", "name"))
    82  }
    83  
    84  func Test_New_CreateComplex(t *testing.T) {
    85  	at := assert.New(t)
    86  
    87  	t.Run("look path error", func(t *testing.T) {
    88  		setupLookPath(errFlag)
    89  		defer teardownLookPath()
    90  
    91  		at.NotNil(createComplex(" ", "name"))
    92  	})
    93  
    94  	t.Run("failed to replace pattern", func(t *testing.T) {
    95  		setupLookPath()
    96  		defer teardownLookPath()
    97  		setupCmd()
    98  		defer teardownCmd()
    99  
   100  		at.NotNil(createComplex(" ", "name"))
   101  	})
   102  }