-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from kcmvp/build-test
#32: fix bug by setting GOPATH as command level
- Loading branch information
Showing
7 changed files
with
93 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package internal | |
import ( | ||
"github.com/samber/lo" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
@@ -11,44 +12,60 @@ import ( | |
var v6 = "golang.org/x/tools/cmd/[email protected]" | ||
var v7 = "golang.org/x/tools/cmd/[email protected]" | ||
|
||
func TestInstallPlugin(t *testing.T) { | ||
type ProjectTestSuit struct { | ||
suite.Suite | ||
goPath string | ||
} | ||
|
||
func TestProjectTestSuit(t *testing.T) { | ||
suite.Run(t, &ProjectTestSuit{ | ||
goPath: GoPath(), | ||
}) | ||
} | ||
|
||
func (suite *ProjectTestSuit) SetupTest() { | ||
os.RemoveAll(suite.goPath) | ||
println(suite.goPath) | ||
} | ||
|
||
func (suite *ProjectTestSuit) TestInstallPlugin() { | ||
CurProject().LoadSettings() | ||
cfg := CurProject().Configuration() | ||
defer func() { | ||
os.Remove(cfg) | ||
}() | ||
err := CurProject().InstallPlugin(v6, "callvis") | ||
assert.NoError(t, err) | ||
gopath := os.Getenv("GOPATH") | ||
assert.NoError(suite.T(), err) | ||
_, name := NormalizePlugin(v6) | ||
_, err = os.Stat(filepath.Join(gopath, "bin", name)) | ||
assert.NoError(t, err) | ||
info, err := os.Stat(filepath.Join(suite.goPath, name)) | ||
assert.NoError(suite.T(), err) | ||
println(info.Name()) | ||
plugin, ok := lo.Find(CurProject().Plugins(), func(item lo.Tuple4[string, string, string, string]) bool { | ||
return item.D == v6 | ||
}) | ||
assert.True(t, ok) | ||
assert.Equal(t, "digraph", plugin.A) | ||
assert.Equal(t, "callvis", plugin.B) | ||
assert.Empty(t, plugin.C) | ||
assert.Equal(t, v6, plugin.D) | ||
assert.True(suite.T(), ok) | ||
assert.Equal(suite.T(), "digraph", plugin.A) | ||
assert.Equal(suite.T(), "callvis", plugin.B) | ||
assert.Empty(suite.T(), plugin.C) | ||
assert.Equal(suite.T(), v6, plugin.D) | ||
|
||
// install same plugin again | ||
err = CurProject().InstallPlugin(v6, "callvis") | ||
assert.Error(t, err) | ||
assert.Error(suite.T(), err) | ||
|
||
// update the plugin | ||
err = CurProject().InstallPlugin(v7, "callvisv7", "run") | ||
assert.NoError(t, err) | ||
assert.NoError(suite.T(), err) | ||
plugin, ok = lo.Find(CurProject().Plugins(), func(item lo.Tuple4[string, string, string, string]) bool { | ||
return item.D == v7 | ||
}) | ||
assert.True(t, ok) | ||
assert.Equal(t, 1, len(CurProject().Plugins())) | ||
assert.Equal(t, plugin.B, "callvisv7") | ||
assert.Equal(t, plugin.C, "run") | ||
assert.True(suite.T(), ok) | ||
assert.Equal(suite.T(), 1, len(CurProject().Plugins())) | ||
assert.Equal(suite.T(), plugin.B, "callvisv7") | ||
assert.Equal(suite.T(), plugin.C, "run") | ||
} | ||
|
||
func TestVersion(t *testing.T) { | ||
//assert.True(t, strings.HasPrefix(Version(), "v0.0.2")) | ||
//assert.True(t, strings.Contains(Version(), "@")) | ||
} | ||
//func TestVersion(t *testing.T) { | ||
// assert.True(t, strings.HasPrefix(Version(), "v0.0.2")) | ||
// assert.True(t, strings.Contains(Version(), "@")) | ||
//} |