Skip to content

Commit 77087f0

Browse files
wip
1 parent ef42f54 commit 77087f0

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

internal/integrationtest/lib/lib_test.go

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"io"
2222
"net/http"
23+
"os"
2324
"runtime"
2425
"strings"
2526
"testing"
@@ -31,6 +32,7 @@ import (
3132
"github.com/go-git/go-git/v5/plumbing/object"
3233
"github.com/stretchr/testify/require"
3334
"go.bug.st/testifyjson/requirejson"
35+
"gopkg.in/src-d/go-git.v4/plumbing"
3436
)
3537

3638
func TestLibUpgradeCommand(t *testing.T) {
@@ -650,36 +652,22 @@ func TestInstallWithGitUrl(t *testing.T) {
650652
}
651653

652654
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+
})
679660
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+
}
683671
}
684672

685673
func TestUpdateIndex(t *testing.T) {

0 commit comments

Comments
 (0)