2020-06-16 09:00:38 +00:00
|
|
|
package build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2020-06-18 08:20:54 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-06-16 09:00:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBasicInstallForModProject(t *testing.T) {
|
2020-06-18 10:08:48 +00:00
|
|
|
workingDir := filepath.Join(baseDir, "../../tests/samples/simple_project")
|
|
|
|
gopath := filepath.Join(baseDir, "../../tests/samples/simple_project", "testhome")
|
2020-06-16 09:00:38 +00:00
|
|
|
|
|
|
|
os.Setenv("GOPATH", gopath)
|
|
|
|
os.Setenv("GO111MODULE", "on")
|
|
|
|
|
2020-06-18 08:20:54 +00:00
|
|
|
buildFlags, packages := "", []string{"."}
|
2020-06-18 09:03:14 +00:00
|
|
|
gocBuild, err := NewInstall(buildFlags, packages, workingDir)
|
2020-06-18 10:08:48 +00:00
|
|
|
if !assert.Equal(t, err, nil) {
|
|
|
|
assert.FailNow(t, "should create temporary directory successfully")
|
|
|
|
}
|
2020-06-16 09:00:38 +00:00
|
|
|
|
|
|
|
err = gocBuild.Install()
|
2020-06-18 10:08:48 +00:00
|
|
|
if !assert.Equal(t, err, nil) {
|
|
|
|
assert.FailNow(t, "temporary directory should build successfully")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidPackageNameForInstall(t *testing.T) {
|
|
|
|
workingDir := filepath.Join(baseDir, "../../tests/samples/simple_project")
|
|
|
|
gopath := filepath.Join(baseDir, "../../tests/samples/simple_project", "testhome")
|
|
|
|
|
|
|
|
os.Setenv("GOPATH", gopath)
|
|
|
|
os.Setenv("GO111MODULE", "on")
|
|
|
|
|
|
|
|
buildFlags, packages := "", []string{"main.go"}
|
|
|
|
_, err := NewInstall(buildFlags, packages, workingDir)
|
|
|
|
if !assert.Equal(t, err, ErrWrongPackageTypeForInstall) {
|
|
|
|
assert.FailNow(t, "should not success with non . or ./... package")
|
|
|
|
}
|
2020-06-16 09:00:38 +00:00
|
|
|
}
|