From 695c90e4812bb7e8c343a2650d4e2cf129061c97 Mon Sep 17 00:00:00 2001 From: kcmvp Date: Mon, 25 Dec 2023 16:10:47 +0800 Subject: [PATCH] test init --- cmd/builder_test.go | 14 +++++--------- cmd/initializer_test.go | 27 +++++++++++++-------------- cmd/plugin_test.go | 17 ----------------- internal/project.go | 6 ------ 4 files changed, 18 insertions(+), 46 deletions(-) diff --git a/cmd/builder_test.go b/cmd/builder_test.go index d1c7f03..e66b0f4 100644 --- a/cmd/builder_test.go +++ b/cmd/builder_test.go @@ -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 { @@ -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") + }) } diff --git a/cmd/initializer_test.go b/cmd/initializer_test.go index 6ff4c16..910b5e3 100644 --- a/cmd/initializer_test.go +++ b/cmd/initializer_test.go @@ -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" @@ -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 diff --git a/cmd/plugin_test.go b/cmd/plugin_test.go index 1555b4e..b2704d9 100644 --- a/cmd/plugin_test.go +++ b/cmd/plugin_test.go @@ -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" ) @@ -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("%s@v1.55.0", 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())) } diff --git a/internal/project.go b/internal/project.go index 52ad7ab..6aea68d 100644 --- a/internal/project.go +++ b/internal/project.go @@ -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()