Skip to content

Commit 5272a17

Browse files
committed
Add more test coverage
1 parent 8cff79d commit 5272a17

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ repository
55
.vagrant
66
keyrings
77
/tmp
8+
.idea
89

910
dist/
1011

internal/config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111

1212
"github.com/mitchellh/go-homedir"
13-
1413
"github.com/sethvargo/go-envconfig"
1514
"gopkg.in/ini.v1"
1615
)

internal/resolve/resolve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func AllVersions(conf config.Config, plugins []plugins.Plugin, directory string)
3838
}
3939
}
4040

41-
// Iterate from the nearest to furthest directory, ending with the user's home.
41+
// Iterate from the current towards the root directory, ending with the user's home.
4242
for iterDir := range iterDirectories(conf, directory) {
4343
// Second: Resolve using the tool versions file
4444
filepath := path.Join(iterDir, conf.DefaultToolVersionsFilename)

internal/resolve/resolve_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ func TestAllVersions(t *testing.T) {
141141
assert.Equal(t, toolVersion[0].Name, unknownPluginName)
142142
assert.Equal(t, toolVersion[0].Versions, []string{"1.2.3"})
143143
})
144+
145+
t.Run("returns results in order from .tool-versions file", func(t *testing.T) {
146+
testPluginTwoName := "dummy_plugin_two"
147+
_, err := repotest.InstallPlugin("dummy_plugin", conf.DataDir, testPluginTwoName)
148+
assert.Nil(t, err)
149+
allPlugins := []plugins.Plugin{plugins.New(conf, testPluginName), plugins.New(conf, testPluginTwoName)}
150+
151+
// write a version file
152+
unknownPluginName := "dummy_unknown_plugin"
153+
data := []byte(fmt.Sprintf("%s 1.2.3\n%s 1.2.3\n%s 1.2.3", testPluginTwoName, testPluginName, unknownPluginName))
154+
err = os.WriteFile(filepath.Join(currentDir, ".tool-versions"), data, 0o666)
155+
assert.Nil(t, err)
156+
157+
toolVersion, err := AllVersions(conf, allPlugins, currentDir)
158+
assert.Nil(t, err)
159+
assert.Equal(t, toolVersion[0].Name, testPluginTwoName)
160+
assert.Equal(t, toolVersion[1].Name, testPluginName)
161+
assert.Equal(t, toolVersion[2].Name, unknownPluginName)
162+
})
144163
}
145164

146165
func TestFindVersionsInDir(t *testing.T) {

0 commit comments

Comments
 (0)