Skip to content

[skip changelog] Add unit test for lib install from git url #1464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions arduino/libraries/librariesmanager/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,17 @@ func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error {
return nil
}

// parseGitURL tries to recover a library name from a git URL.
// Returns an error in case the URL is not a valid git URL.
func parseGitURL(gitURL string) (string, error) {
var res string
if strings.HasPrefix(gitURL, "git@") {
// We can't parse these as URLs
i := strings.LastIndex(gitURL, "/")
res = strings.TrimSuffix(gitURL[i+1:], ".git")
} else if path := paths.New(gitURL); path.Exist() {
} else if path := paths.New(gitURL); path != nil && path.Exist() {
res = path.Base()
} else if parsed, err := url.Parse(gitURL); err == nil {
} else if parsed, err := url.Parse(gitURL); parsed.String() != "" && err == nil {
i := strings.LastIndex(parsed.Path, "/")
res = strings.TrimSuffix(parsed.Path[i+1:], ".git")
} else {
Expand Down
64 changes: 64 additions & 0 deletions arduino/libraries/librariesmanager/install_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package librariesmanager

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestParseGitURL(t *testing.T) {
gitURL := ""
libraryName, err := parseGitURL(gitURL)
require.Equal(t, "", libraryName)
require.Errorf(t, err, "invalid git url")

gitURL = "https://github.com/arduino/arduino-lib.git"
libraryName, err = parseGitURL(gitURL)
require.Equal(t, "arduino-lib", libraryName)
require.NoError(t, err)

gitURL = "git@github.com:arduino/arduino-lib.git"
libraryName, err = parseGitURL(gitURL)
require.Equal(t, "arduino-lib", libraryName)
require.NoError(t, err)

gitURL = "file:///path/to/arduino-lib"
libraryName, err = parseGitURL(gitURL)
require.Equal(t, "arduino-lib", libraryName)
require.NoError(t, err)

gitURL = "file:///path/to/arduino-lib.git"
libraryName, err = parseGitURL(gitURL)
require.Equal(t, "arduino-lib", libraryName)
require.NoError(t, err)

gitURL = "/path/to/arduino-lib"
libraryName, err = parseGitURL(gitURL)
require.Equal(t, "arduino-lib", libraryName)
require.NoError(t, err)

gitURL = "/path/to/arduino-lib.git"
libraryName, err = parseGitURL(gitURL)
require.Equal(t, "arduino-lib", libraryName)
require.NoError(t, err)

gitURL = "file:///path/to/arduino-lib"
libraryName, err = parseGitURL(gitURL)
require.Equal(t, "arduino-lib", libraryName)
require.NoError(t, err)
}
6 changes: 3 additions & 3 deletions i18n/data/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -2755,7 +2755,7 @@ msgstr "invalid empty library version: %s"
msgid "invalid empty option found"
msgstr "invalid empty option found"

#: arduino/libraries/librariesmanager/install.go:255
#: arduino/libraries/librariesmanager/install.go:257
msgid "invalid git url"
msgstr "invalid git url"

Expand Down Expand Up @@ -2828,11 +2828,11 @@ msgstr "library %s already installed"
msgid "library already installed"
msgstr "library already installed"

#: arduino/libraries/librariesmanager/install.go:274
#: arduino/libraries/librariesmanager/install.go:276
msgid "library is not valid: missing file \"library.properties\""
msgstr "library is not valid: missing file \"library.properties\""

#: arduino/libraries/librariesmanager/install.go:269
#: arduino/libraries/librariesmanager/install.go:271
msgid "library is not valid: missing header file \"%s\""
msgstr "library is not valid: missing header file \"%s\""

Expand Down
14 changes: 7 additions & 7 deletions i18n/rice-box.go

Large diffs are not rendered by default.