@@ -2,6 +2,7 @@ package bine
22
33import (
44 "context"
5+ "errors"
56 "os"
67 "path/filepath"
78 "testing"
@@ -136,3 +137,91 @@ func TestUpgradeFailsSafelyWhenLatestMarkerCannotBeRemoved(t *testing.T) {
136137 _ , statErr := os .Stat (binPath )
137138 assert .NilError (t , statErr )
138139}
140+
141+ func TestListOneScopesOutdatedChecksToTargetBin (t * testing.T ) {
142+ configPath := filepath .Join (t .TempDir (), ".bine.json" )
143+ assert .NilError (t , os .WriteFile (configPath , []byte ("{}" ), 0o640 ))
144+
145+ b := & Bine {
146+ config : & config {
147+ path : configPath ,
148+ Bins : []* bin {
149+ {
150+ Name : "broken" ,
151+ GoPackage : "github.com/foo/bar/cmd/broken" ,
152+ Version : "1.0.0" ,
153+ provider : staticProvider {err : errors .New ("boom" )},
154+ },
155+ {
156+ Name : "tool" ,
157+ GoPackage : "github.com/foo/bar/cmd/tool" ,
158+ Version : "1.0.0" ,
159+ provider : staticProvider {latest : "2.0.0" },
160+ },
161+ },
162+ },
163+ }
164+
165+ items , err := b .ListOne (t .Context (), "tool" , false , true )
166+ assert .NilError (t , err )
167+ assert .Equal (t , len (items ), 1 )
168+ assert .Equal (t , items [0 ].Name , "tool" )
169+ assert .Equal (t , items [0 ].Latest , "v2.0.0" )
170+ }
171+
172+ func TestUpgradeOneOnlyUpdatesRequestedBin (t * testing.T ) {
173+ injectFakeExec (t , "TestHelperProcessWithSuccess" )
174+
175+ cacheDir := t .TempDir ()
176+ configPath := filepath .Join (cacheDir , ".bine.json" )
177+ assert .NilError (t , os .WriteFile (configPath , []byte (`{
178+ "project": "test",
179+ "bins": [
180+ {"name": "tool", "go_package": "github.com/foo/bar/cmd/tool", "version": "1.0.0"},
181+ {"name": "other", "go_package": "github.com/foo/bar/cmd/other", "version": "1.0.0"}
182+ ]
183+ }` ), 0o640 ))
184+
185+ b := & Bine {
186+ BinDir : filepath .Join (cacheDir , "bin" ),
187+ VersionsDir : filepath .Join (cacheDir , "versions" ),
188+ config : & config {
189+ path : configPath ,
190+ Bins : []* bin {
191+ {
192+ Name : "tool" ,
193+ GoPackage : "github.com/foo/bar/cmd/tool" ,
194+ Version : "1.0.0" ,
195+ provider : staticProvider {latest : "2.0.0" },
196+ },
197+ {
198+ Name : "other" ,
199+ GoPackage : "github.com/foo/bar/cmd/other" ,
200+ Version : "1.0.0" ,
201+ provider : staticProvider {latest : "3.0.0" },
202+ },
203+ },
204+ },
205+ }
206+
207+ updates , err := b .UpgradeOne (t .Context (), "tool" )
208+ assert .NilError (t , err )
209+ assert .Equal (t , len (updates ), 1 )
210+ assert .Equal (t , updates [0 ].Name , "tool" )
211+ assert .Equal (t , updates [0 ].Latest , "v2.0.0" )
212+
213+ configBlob , err := os .ReadFile (configPath )
214+ assert .NilError (t , err )
215+ assert .Equal (t , string (configBlob ), `{
216+ "project": "test",
217+ "bins": [
218+ {"name": "tool", "go_package": "github.com/foo/bar/cmd/tool", "version": "2.0.0"},
219+ {"name": "other", "go_package": "github.com/foo/bar/cmd/other", "version": "1.0.0"}
220+ ]
221+ }` )
222+
223+ _ , err = os .Stat (filepath .Join (b .BinDir , "tool" ))
224+ assert .NilError (t , err )
225+ _ , err = os .Stat (filepath .Join (b .BinDir , "other" ))
226+ assert .Assert (t , os .IsNotExist (err ))
227+ }
0 commit comments