github.com/wiselike/revel-cmd@v1.2.1/revel/build_test.go (about)

     1  package main_test
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/wiselike/revel-cmd/model"
     9  	main "github.com/wiselike/revel-cmd/revel"
    10  	"github.com/wiselike/revel-cmd/utils"
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  // test the commands.
    15  func TestBuild(t *testing.T) {
    16  	a := assert.New(t)
    17  	gopath := setup("revel-test-build", a)
    18  
    19  	t.Run("Build", func(t *testing.T) {
    20  		a := assert.New(t)
    21  		c := newApp("build-test", model.NEW, nil, a)
    22  		a.Nil(main.Commands[model.NEW].RunWith(c), "failed to run new")
    23  		c.Index = model.BUILD
    24  		c.Build.TargetPath = filepath.Join(gopath, "build-test", "target")
    25  		c.Build.ImportPath = c.ImportPath
    26  		a.Nil(main.Commands[model.BUILD].RunWith(c), "Failed to run build-test")
    27  		a.True(utils.Exists(filepath.Join(gopath, "build-test", "target")))
    28  	})
    29  
    30  	t.Run("Build-withFlags", func(t *testing.T) {
    31  		a := assert.New(t)
    32  		c := newApp("build-test-WithFlags", model.NEW, nil, a)
    33  		c.BuildFlags = []string{
    34  			"build-test-WithFlags/app.AppVersion=SomeValue",
    35  			"build-test-WithFlags/app.SomeOtherValue=SomeValue",
    36  		}
    37  		a.Nil(main.Commands[model.NEW].RunWith(c), "failed to run new")
    38  		c.Index = model.BUILD
    39  		c.Build.TargetPath = filepath.Join(gopath, "build-test", "target")
    40  		c.Build.ImportPath = c.ImportPath
    41  		a.Nil(main.Commands[model.BUILD].RunWith(c), "Failed to run build-test-withFlags")
    42  		a.True(utils.Exists(filepath.Join(gopath, "build-test", "target")))
    43  	})
    44  
    45  	if !t.Failed() {
    46  		if err := os.RemoveAll(gopath); err != nil {
    47  			a.Fail("Failed to remove test path")
    48  		}
    49  	}
    50  }