github.com/yuki2006/cmd@v0.12.1-0.20240406021944-1e791c677ee9/revel/version_test.go (about)

     1  package main_test
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/yuki2006/cmd/model"
    11  	main "github.com/yuki2006/cmd/revel"
    12  )
    13  
    14  // test the commands.
    15  func TestVersion(t *testing.T) {
    16  	a := assert.New(t)
    17  	gopath := setup("revel-test-version", a)
    18  
    19  	t.Run("Version", func(t *testing.T) {
    20  		a := assert.New(t)
    21  		c := newApp("version-test", model.NEW, nil, a)
    22  		a.Nil(main.Commands[model.NEW].RunWith(c), "Check new")
    23  		c.Build.ImportPath = c.ImportPath
    24  		c.Build.TargetPath = filepath.Join(gopath, "build-test", "target")
    25  		a.Nil(main.Commands[model.BUILD].RunWith(c), "Failed to run build")
    26  		c.Index = model.VERSION
    27  		c.Version.ImportPath = c.ImportPath
    28  		a.Nil(main.Commands[model.VERSION].RunWith(c), "Failed to run version-test")
    29  	})
    30  	t.Run("Version-Nobuild", func(t *testing.T) {
    31  		a := assert.New(t)
    32  		c := newApp("version-test2", model.NEW, nil, a)
    33  		a.Nil(main.Commands[model.NEW].RunWith(c), "Check new")
    34  		c.Index = model.VERSION
    35  		c.Version.ImportPath = c.ImportPath
    36  		a.Nil(main.Commands[model.VERSION].RunWith(c), "Failed to run version-test")
    37  	})
    38  
    39  	if !t.Failed() {
    40  		if err := os.RemoveAll(gopath); err != nil && !errors.Is(err, os.ErrNotExist) {
    41  			a.Fail("Failed to remove test path", err.Error())
    42  		}
    43  	}
    44  }