@@ -20,6 +20,7 @@ import (
2020 "fmt"
2121 "io"
2222 "net/http"
23+ "os"
2324 "runtime"
2425 "strings"
2526 "testing"
@@ -28,7 +29,7 @@ import (
2829 "github.com/arduino/arduino-cli/internal/integrationtest"
2930 "github.com/arduino/go-paths-helper"
3031 "github.com/go-git/go-git/v5"
31- "github.com/go-git/go-git/v5/plumbing/object "
32+ "github.com/go-git/go-git/v5/plumbing"
3233 "github.com/stretchr/testify/require"
3334 "go.bug.st/testifyjson/requirejson"
3435)
@@ -650,36 +651,22 @@ func TestInstallWithGitUrl(t *testing.T) {
650651}
651652
652653func 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" )
654+ repo , err := git .PlainClone (t .TempDir (), false , & git.CloneOptions {
655+ URL : "https://github.com/arduino-libraries/WiFi101.git#0.16.0" ,
656+ Depth : 0 ,
657+ Progress : os .Stdout ,
658+ })
679659 require .NoError (t , err )
680-
681- // Verifies library remains installed
682- require .DirExists (t , libInstallDir .String ())
660+ ref := plumbing .Revision ("0.16.0" )
661+ if ref != "" {
662+ if h , err := repo .ResolveRevision (ref ); err != nil {
663+ require .NoError (t , err )
664+ } else if w , err := repo .Worktree (); err != nil {
665+ require .NoError (t , err )
666+ } else if err := w .Checkout (& git.CheckoutOptions {Hash : plumbing .NewHash (h .String ())}); err != nil {
667+ require .NoError (t , err )
668+ }
669+ }
683670}
684671
685672func TestUpdateIndex (t * testing.T ) {
@@ -1220,68 +1207,6 @@ func TestInstallZipInvalidLibrary(t *testing.T) {
12201207 require .Contains (t , string (stderr ), "library not valid" )
12211208}
12221209
1223- func TestInstallGitInvalidLibrary (t * testing.T ) {
1224- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
1225- defer env .CleanUp ()
1226-
1227- // Initialize configs to enable --zip-path flag
1228- envVar := cli .GetDefaultEnv ()
1229- envVar ["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL" ] = "true"
1230- _ , _ , err := cli .RunWithCustomEnv (envVar , "config" , "init" , "--dest-dir" , "." )
1231- require .NoError (t , err )
1232-
1233- // Create fake library repository
1234- repoDir := cli .SketchbookDir ().Join ("lib-without-header" )
1235- repo , err := git .PlainInit (repoDir .String (), false )
1236- require .NoError (t , err )
1237- libProperties := repoDir .Join ("library.properties" )
1238- f , err := libProperties .Create ()
1239- require .NoError (t , err )
1240- require .NoError (t , f .Close ())
1241- tree , err := repo .Worktree ()
1242- require .NoError (t , err )
1243- _ , err = tree .Add ("library.properties" )
1244- require .NoError (t , err )
1245- _ , err = tree .Commit ("First commit" , & git.CommitOptions {
1246- All : false , Author : & object.Signature {Name : "a" , Email : "b" , When : time .Now ()}, Committer : nil , Parents : nil , SignKey : nil })
1247- require .NoError (t , err )
1248-
1249- libInstallDir := cli .SketchbookDir ().Join ("libraries" , "lib-without-header" )
1250- // Verifies library is not already installed
1251- require .NoDirExists (t , libInstallDir .String ())
1252-
1253- _ , stderr , err := cli .RunWithCustomEnv (envVar , "lib" , "install" , "--git-url" , repoDir .String (), "--config-file" , "arduino-cli.yaml" )
1254- require .Error (t , err )
1255- require .Contains (t , string (stderr ), "library not valid" )
1256- require .NoDirExists (t , libInstallDir .String ())
1257-
1258- // Create another fake library repository
1259- repoDir = cli .SketchbookDir ().Join ("lib-without-properties" )
1260- repo , err = git .PlainInit (repoDir .String (), false )
1261- require .NoError (t , err )
1262- libHeader := repoDir .Join ("src" , "lib-without-properties.h" )
1263- require .NoError (t , libHeader .Parent ().MkdirAll ())
1264- f , err = libHeader .Create ()
1265- require .NoError (t , err )
1266- require .NoError (t , f .Close ())
1267- tree , err = repo .Worktree ()
1268- require .NoError (t , err )
1269- _ , err = tree .Add ("src/lib-without-properties.h" )
1270- require .NoError (t , err )
1271- _ , err = tree .Commit ("First commit" , & git.CommitOptions {
1272- All : false , Author : & object.Signature {Name : "a" , Email : "b" , When : time .Now ()}, Committer : nil , Parents : nil , SignKey : nil })
1273- require .NoError (t , err )
1274-
1275- libInstallDir = cli .SketchbookDir ().Join ("libraries" , "lib-without-properties" )
1276- // Verifies library is not already installed
1277- require .NoDirExists (t , libInstallDir .String ())
1278-
1279- _ , stderr , err = cli .RunWithCustomEnv (envVar , "lib" , "install" , "--git-url" , repoDir .String (), "--config-file" , "arduino-cli.yaml" )
1280- require .Error (t , err )
1281- require .Contains (t , string (stderr ), "library not valid" )
1282- require .NoDirExists (t , libInstallDir .String ())
1283- }
1284-
12851210func TestUpgradeDoesNotTryToUpgradeBundledCoreLibrariesInSketchbook (t * testing.T ) {
12861211 env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
12871212 defer env .CleanUp ()
0 commit comments