github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/builtin/app/go/app_test.go (about)

     1  package goapp
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/otto/app"
     9  	"github.com/hashicorp/otto/helper/compile"
    10  	"github.com/hashicorp/otto/otto"
    11  )
    12  
    13  func TestApp_impl(t *testing.T) {
    14  	var _ app.App = new(App)
    15  }
    16  
    17  func TestApp_importPath_noGOPATH(t *testing.T) {
    18  	compile.AppTest(true)
    19  	defer compile.AppTest(false)
    20  
    21  	// No GOPATH can be set
    22  	defer os.Setenv("GOPATH", os.Getenv("GOPATH"))
    23  	os.Setenv("GOPATH", "")
    24  
    25  	otto.Test(t, otto.TestCase{
    26  		Unit: true,
    27  		Core: otto.TestCore(t, &otto.TestCoreOpts{
    28  			Path: filepath.Join("./test-fixtures", "basic", "Appfile"),
    29  			App:  new(App),
    30  		}),
    31  
    32  		Steps: []otto.TestStep{
    33  			&compile.AppTestStepContext{
    34  				Key:   "import_path",
    35  				Value: "",
    36  			},
    37  
    38  			&compile.AppTestStepContext{
    39  				Key:   "shared_folder_path",
    40  				Value: "/vagrant",
    41  			},
    42  		},
    43  	})
    44  }
    45  
    46  func TestApp_importPath(t *testing.T) {
    47  	gopath := filepath.Join("./test-fixtures", "gopath")
    48  
    49  	compile.AppTest(true)
    50  	defer compile.AppTest(false)
    51  
    52  	// No GOPATH can be set
    53  	defer os.Setenv("GOPATH", os.Getenv("GOPATH"))
    54  	os.Setenv("GOPATH", gopath)
    55  
    56  	otto.Test(t, otto.TestCase{
    57  		Unit: true,
    58  		Core: otto.TestCore(t, &otto.TestCoreOpts{
    59  			Path: filepath.Join(gopath, "src", "example.com", "Appfile"),
    60  			App:  new(App),
    61  		}),
    62  
    63  		Steps: []otto.TestStep{
    64  			&compile.AppTestStepContext{
    65  				Key:   "import_path",
    66  				Value: "example.com",
    67  			},
    68  
    69  			&compile.AppTestStepContext{
    70  				Key:   "shared_folder_path",
    71  				Value: "/opt/gopath/src/example.com",
    72  			},
    73  		},
    74  	})
    75  }