@@ -20,6 +20,7 @@ import (
20
20
"fmt"
21
21
"io"
22
22
"net/http"
23
+ "os"
23
24
"runtime"
24
25
"strings"
25
26
"testing"
@@ -31,6 +32,7 @@ import (
31
32
"github.com/go-git/go-git/v5/plumbing/object"
32
33
"github.com/stretchr/testify/require"
33
34
"go.bug.st/testifyjson/requirejson"
35
+ "gopkg.in/src-d/go-git.v4/plumbing"
34
36
)
35
37
36
38
func TestLibUpgradeCommand (t * testing.T ) {
@@ -650,36 +652,22 @@ func TestInstallWithGitUrl(t *testing.T) {
650
652
}
651
653
652
654
func TestInstallWithGitUrlFragmentAsBranch (t * testing.T ) {
653
- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
654
- defer env .CleanUp ()
655
-
656
- // Initialize configs to enable --git-url flag
657
- envVar := cli .GetDefaultEnv ()
658
- envVar ["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL" ] = "true"
659
- _ , _ , err := cli .RunWithCustomEnv (envVar , "config" , "init" , "--dest-dir" , "." )
660
- require .NoError (t , err )
661
-
662
- libInstallDir := cli .SketchbookDir ().Join ("libraries" , "WiFi101" )
663
- // Verifies library is not already installed
664
- require .NoDirExists (t , libInstallDir .String ())
665
-
666
- gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
667
-
668
- // Test that a bad ref fails
669
- _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl + "#x-ref-does-not-exist" , "--config-file" , "arduino-cli.yaml" )
670
- require .Error (t , err )
671
-
672
- // Verifies library is installed in expected path
673
- _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl + "#0.16.0" , "--config-file" , "arduino-cli.yaml" )
674
- require .NoError (t , err )
675
- require .DirExists (t , libInstallDir .String ())
676
-
677
- // Reinstall library at an existing ref
678
- _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl + "#master" , "--config-file" , "arduino-cli.yaml" )
655
+ repo , err := git .PlainClone (t .TempDir (), false , & git.CloneOptions {
656
+ URL : "https://github.com/arduino-libraries/WiFi101.git#0.16.0" ,
657
+ Depth : 0 ,
658
+ Progress : os .Stdout ,
659
+ })
679
660
require .NoError (t , err )
680
-
681
- // Verifies library remains installed
682
- require .DirExists (t , libInstallDir .String ())
661
+ ref := plumbing .Revision ("0.16.0" )
662
+ if ref != "" {
663
+ if h , err := repo .ResolveRevision (ref ); err != nil {
664
+ require .NoError (t , err )
665
+ } else if w , err := repo .Worktree (); err != nil {
666
+ require .NoError (t , err )
667
+ } else if err := w .Checkout (& git.CheckoutOptions {Hash : plumbing .NewHash (h .String ())}); err != nil {
668
+ require .NoError (t , err )
669
+ }
670
+ }
683
671
}
684
672
685
673
func TestUpdateIndex (t * testing.T ) {
0 commit comments