Skip to content

Commit

Permalink
test init
Browse files Browse the repository at this point in the history
  • Loading branch information
kcmvp committed Dec 25, 2023
1 parent 1fe9629 commit 695c90e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 46 deletions.
14 changes: 5 additions & 9 deletions cmd/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ func TestBuilderTestSuit(t *testing.T) {
})
}

//func (suite *BuilderTestSuit) SetupSuite() {
// internal.CurProject().Load(filepath.Join(internal.CurProject().Root(), "testdata", "gob.yaml"))
//}

func (suite *BuilderTestSuit) TestPersistentPreRun() {
builderCmd.PersistentPreRun(nil, nil)
hooks := lo.MapToSlice(internal.HookScripts, func(key string, _ string) string {
Expand All @@ -45,9 +41,9 @@ func (suite *BuilderTestSuit) TestPersistentPreRun() {
//fmt.Println(internal.CurProject().Configuration())
fmt.Println(internal.CurProject().Plugins())
// test the missing plugins installation
//lo.ForEach(internal.CurProject().Plugins(), func(plugin lo.Tuple4[string, string, string, string], index int) {
// _, name := internal.NormalizePlugin(plugin.D)
// _, err := os.Stat(filepath.Join(suite.gopath, "bin", name))
// assert.NoErrorf(suite.T(), err, "plugin should be insalled")
//})
lo.ForEach(internal.CurProject().Plugins(), func(plugin lo.Tuple4[string, string, string, string], index int) {
_, name := internal.NormalizePlugin(plugin.D)
_, err := os.Stat(filepath.Join(suite.gopath, "bin", name))
assert.NoErrorf(suite.T(), err, "plugin should be insalled")
})
}
27 changes: 13 additions & 14 deletions cmd/initializer_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//go:build ignore

package cmd

import (
"bufio"
"github.com/kcmvp/gb/internal"
"github.com/kcmvp/gob/internal"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -48,17 +47,17 @@ func (suite *InitializationTestSuite) TestInitializeHook() {
assert.True(suite.T(), hasLint)
assert.True(suite.T(), hasAlias)
// verify plugin
//var installed bool
//filepath.WalkDir(filepath.Join(suite.gopath, "bin"), func(path string, d fs.DirEntry, err error) error {
// if err != nil {
// return err
// }
// if installed = strings.HasPrefix(d.Name(), "golangci-lint-"); installed {
// return filepath.SkipDir
// }
// return nil
//})
//assert.True(suite.T(), installed)
var installed bool
filepath.WalkDir(filepath.Join(suite.gopath, "bin"), func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if installed = strings.HasPrefix(d.Name(), "golangci-lint-"); installed {
return filepath.SkipDir
}
return nil
})
assert.True(suite.T(), installed)
// verify hook
hooks := lo.MapToSlice(internal.HookScripts, func(key string, _ string) string {
return key
Expand Down
17 changes: 0 additions & 17 deletions cmd/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package cmd

import (
"bytes"
"fmt"
"github.com/kcmvp/gob/internal"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
)

Expand Down Expand Up @@ -76,19 +74,4 @@ func TestInstallPlugin(t *testing.T) {
assert.Equal(t, fiximports, plugin.D)
assert.Equal(t, 2, len(internal.CurProject().Plugins()))

// install golangci-lint plugin
builderCmd.SetArgs([]string{"plugin", "install", fmt.Sprintf("%[email protected]", golangCiLinter), "-a=lint", "-c=lint-run"})
err = builderCmd.Execute()
assert.NoError(t, err)
builderCmd.SetArgs([]string{"plugin"})
err = builderCmd.Execute()
assert.NoError(t, err)
plugin, ok = lo.Find(internal.CurProject().Plugins(), func(item lo.Tuple4[string, string, string, string]) bool {
return strings.HasPrefix(item.D, golangCiLinter)
})
assert.Equal(t, "golangci-lint", plugin.A)
assert.Equal(t, "lint", plugin.B)
assert.Equal(t, "lint-run", plugin.C)
assert.True(t, strings.HasPrefix(plugin.D, golangCiLinter))
assert.Equal(t, 3, len(internal.CurProject().Plugins()))
}
6 changes: 0 additions & 6 deletions internal/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ func (project *Project) HookDir() string {
}
}

// Load a specified file. for test only
func (project *Project) Load(file string) {
f, _ := os.Open(file)
project.viper.ReadConfig(f)
}

func (project *Project) LoadSettings() {
testEnv, _ := TestCallee()
v := viper.New()
Expand Down

0 comments on commit 695c90e

Please sign in to comment.