@@ -48,35 +48,67 @@ func TestInstallPath(t *testing.T) {
48
48
}
49
49
50
50
func TestInstalled (t * testing.T ) {
51
- conf , plugin := generateConfig (t )
52
-
53
51
t .Run ("returns empty slice for newly installed plugin" , func (t * testing.T ) {
52
+ conf , plugin := generateConfig (t )
54
53
installedVersions , err := Installed (conf , plugin )
55
54
assert .Nil (t , err )
56
55
assert .Empty (t , installedVersions )
57
56
})
58
57
59
58
t .Run ("returns slice of all installed versions for a tool" , func (t * testing.T ) {
59
+ conf , plugin := generateConfig (t )
60
60
mockInstall (t , conf , plugin , "1.0.0" )
61
61
62
62
installedVersions , err := Installed (conf , plugin )
63
63
assert .Nil (t , err )
64
64
assert .Equal (t , installedVersions , []string {"1.0.0" })
65
65
})
66
+
67
+ t .Run ("returns installed versions including symlinks" , func (t * testing.T ) {
68
+ conf , plugin := generateConfig (t )
69
+ mockInstall (t , conf , plugin , "1.0.0" )
70
+ aliasVersion (t , conf , plugin , "1.0.0" , "latest" )
71
+
72
+ installedVersions , err := Installed (conf , plugin )
73
+ assert .Nil (t , err )
74
+ assert .Equal (t , installedVersions , []string {"1.0.0" , "latest" })
75
+ })
66
76
}
67
77
68
78
func TestIsInstalled (t * testing.T ) {
69
- conf , plugin := generateConfig (t )
70
- installVersion (t , conf , plugin , "1.0.0" )
71
-
72
79
t .Run ("returns false when not installed" , func (t * testing.T ) {
80
+ conf , plugin := generateConfig (t )
81
+ installVersion (t , conf , plugin , "1.0.0" )
82
+
73
83
version := toolversions.Version {Type : "version" , Value : "4.0.0" }
74
84
assert .False (t , IsInstalled (conf , plugin , version ))
75
85
})
86
+
76
87
t .Run ("returns true when installed" , func (t * testing.T ) {
88
+ conf , plugin := generateConfig (t )
89
+ installVersion (t , conf , plugin , "1.0.0" )
90
+
77
91
version := toolversions.Version {Type : "version" , Value : "1.0.0" }
78
92
assert .True (t , IsInstalled (conf , plugin , version ))
79
93
})
94
+
95
+ t .Run ("returns true when aliased using symlinks" , func (t * testing.T ) {
96
+ conf , plugin := generateConfig (t )
97
+ installVersion (t , conf , plugin , "1.0.0" )
98
+ aliasVersion (t , conf , plugin , "1.0.0" , "latest" )
99
+
100
+ version := toolversions.Version {Type : "alias" , Value : "latest" }
101
+ assert .True (t , IsInstalled (conf , plugin , version ))
102
+ })
103
+
104
+ t .Run ("returns false when symlink broken" , func (t * testing.T ) {
105
+ conf , plugin := generateConfig (t )
106
+ installVersion (t , conf , plugin , "1.0.0" )
107
+ aliasVersion (t , conf , plugin , "2.0.0" , "latest" )
108
+
109
+ version := toolversions.Version {Type : "alias" , Value : "latest" }
110
+ assert .False (t , IsInstalled (conf , plugin , version ))
111
+ })
80
112
}
81
113
82
114
// helper functions
@@ -101,6 +133,14 @@ func mockInstall(t *testing.T, conf config.Config, plugin plugins.Plugin, versio
101
133
assert .Nil (t , err )
102
134
}
103
135
136
+ func aliasVersion (t * testing.T , conf config.Config , plugin plugins.Plugin , versionStr , aliasStr string ) {
137
+ t .Helper ()
138
+ originPath := InstallPath (conf , plugin , toolversions.Version {Type : "version" , Value : versionStr })
139
+ aliasPath := InstallPath (conf , plugin , toolversions.Version {Type : "version" , Value : aliasStr })
140
+ err := os .Symlink (originPath , aliasPath )
141
+ assert .Nil (t , err )
142
+ }
143
+
104
144
func installVersion (t * testing.T , conf config.Config , plugin plugins.Plugin , version string ) {
105
145
t .Helper ()
106
146
err := installtest .InstallOneVersion (conf , plugin , "version" , version )
0 commit comments