Skip to content

Commit 81a15cf

Browse files
committed
Expose registry handling API externally
Since they were intended only for use in the "sync_libraries" application, the module's packages were made `internal` to clearly communicate that they are not part of a public API so that we will not need to be concerned with unintentional impacts on other projects if breaking changes to the internal API are required in the course of development on the code base. Select parts of the API may be exposed externally as they are determined to be useful for other projects. Such a case has arisen with the need to validate the library registry data file format.
1 parent e6fed30 commit 81a15cf

File tree

4 files changed

+176
-104
lines changed

4 files changed

+176
-104
lines changed

internal/libraries/repolist_test.go

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -26,113 +26,9 @@ package libraries
2626
import (
2727
"testing"
2828

29-
"github.com/stretchr/testify/assert"
3029
"github.com/stretchr/testify/require"
3130
)
3231

33-
func TestLoadRepoListFromFile(t *testing.T) {
34-
_, err := LoadRepoListFromFile("./testdata/nonexistent.txt")
35-
assert.Error(t, err, "Attempt to load non-existent registry data file")
36-
37-
repos, err := LoadRepoListFromFile("./testdata/git_test_repos.txt")
38-
require.NoError(t, err)
39-
40-
reposAssertion := []*Repo{
41-
{
42-
URL: "https://github.com/arduino-libraries",
43-
Types: []string{"Arduino"},
44-
LibraryName: "libraries",
45-
},
46-
{
47-
URL: "[email protected]:PaulStoffregen/Audio.git",
48-
Types: []string{"Contributed"},
49-
LibraryName: "Audio",
50-
},
51-
{
52-
URL: "https://github.com/PaulStoffregen/OctoWS2811.git",
53-
Types: []string{"Arduino", "Contributed"},
54-
LibraryName: "OctoWS2811",
55-
},
56-
{
57-
URL: "https://github.com/PaulStoffregen/AltSoftSerial.git",
58-
Types: []string{"Contributed"},
59-
LibraryName: "AltSoftSerial",
60-
},
61-
{
62-
URL: "https://github.com/Cheong2K/ble-sdk-arduino.git",
63-
Types: []string{"Contributed"},
64-
LibraryName: "ble-sdk-arduino",
65-
},
66-
{
67-
URL: "https://github.com/arduino-libraries/Bridge.git",
68-
Types: []string{"Contributed"},
69-
LibraryName: "Bridge",
70-
},
71-
{
72-
URL: "https://github.com/adafruit/Adafruit_ADS1X15.git",
73-
Types: []string{"Recommended"},
74-
LibraryName: "Adafruit_ADS1X15",
75-
},
76-
{
77-
URL: "https://github.com/adafruit/Adafruit_ADXL345.git",
78-
Types: []string{"Recommended"},
79-
LibraryName: "Adafruit_ADXL345",
80-
},
81-
{
82-
URL: "https://github.com/adafruit/Adafruit_AHRS.git",
83-
Types: []string{"Recommended"},
84-
LibraryName: "Adafruit_AHRS",
85-
},
86-
{
87-
URL: "https://github.com/adafruit/Adafruit_AM2315.git",
88-
Types: []string{"Recommended"},
89-
LibraryName: "Adafruit_AM2315",
90-
},
91-
{
92-
URL: "https://github.com/arduino-libraries/Scheduler.git",
93-
Types: []string{"Arduino"},
94-
LibraryName: "Scheduler",
95-
},
96-
{
97-
URL: "https://github.com/arduino-libraries/SD.git",
98-
Types: []string{"Arduino"},
99-
LibraryName: "SD",
100-
},
101-
{
102-
URL: "https://github.com/arduino-libraries/Servo.git",
103-
Types: []string{"Arduino"},
104-
LibraryName: "Servo",
105-
},
106-
}
107-
108-
assert.Equal(t, reposAssertion, repos)
109-
}
110-
111-
func TestListRepos(t *testing.T) {
112-
repos, err := ListRepos("./testdata/git_test_repos.txt")
113-
114-
require.Equal(t, 11, len(repos))
115-
116-
require.Equal(t, "https://github.com/PaulStoffregen/OctoWS2811.git", repos[0].URL)
117-
require.Equal(t, "https://github.com/PaulStoffregen/AltSoftSerial.git", repos[1].URL)
118-
119-
require.Equal(t, "https://github.com/Cheong2K/ble-sdk-arduino.git", repos[2].URL)
120-
require.Equal(t, "https://github.com/arduino-libraries/Bridge.git", repos[3].URL)
121-
require.Equal(t, "https://github.com/adafruit/Adafruit_ADS1X15.git", repos[4].URL)
122-
require.Equal(t, "https://github.com/adafruit/Adafruit_ADXL345.git", repos[5].URL)
123-
require.Equal(t, "https://github.com/adafruit/Adafruit_AHRS.git", repos[6].URL)
124-
require.Equal(t, "https://github.com/adafruit/Adafruit_AM2315.git", repos[7].URL)
125-
require.Equal(t, "https://github.com/arduino-libraries/Scheduler.git", repos[8].URL)
126-
require.Equal(t, "https://github.com/arduino-libraries/SD.git", repos[9].URL)
127-
require.Equal(t, "https://github.com/arduino-libraries/Servo.git", repos[10].URL)
128-
require.Error(t, err)
129-
130-
error, ok := err.(GitURLsError)
131-
require.True(t, ok)
132-
require.Equal(t, "https://github.com/arduino-libraries", error.Repos[0].URL)
133-
require.Equal(t, "[email protected]:PaulStoffregen/Audio.git", error.Repos[1].URL)
134-
}
135-
13632
func TestRepoFolderPathDetermination(t *testing.T) {
13733
repo := &Repo{URL: "https://github.com/arduino-libraries/Servo.git"}
13834
f, err := repo.AsFolder()

libraries/repolist.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of libraries-repository-engine.
2+
//
3+
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published
7+
// by the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
//
18+
// You can be released from the requirements of the above licenses by purchasing
19+
// a commercial license. Buying such a license is mandatory if you want to
20+
// modify or otherwise use the software for commercial activities involving the
21+
// Arduino software without disclosing the source code of your own applications.
22+
// To purchase a commercial license, send an email to [email protected].
23+
24+
package libraries
25+
26+
import (
27+
"arduino.cc/repository/internal/libraries"
28+
)
29+
30+
// LoadRepoListFromFile returns an unfiltered list of library registry entries loaded from the given data file.
31+
func LoadRepoListFromFile(filename string) ([]*Repo, error) {
32+
return libraries.LoadRepoListFromFile(filename)
33+
}
34+
35+
// Repo is the type for the library repository data.
36+
type Repo = libraries.Repo
37+
38+
// ListRepos returns a filtered list of library registry entries loaded from the given data file.
39+
func ListRepos(reposFilename string) ([]*Repo, error) {
40+
return libraries.ListRepos(reposFilename)
41+
}

libraries/repolist_test.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// This file is part of libraries-repository-engine.
2+
//
3+
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published
7+
// by the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
//
18+
// You can be released from the requirements of the above licenses by purchasing
19+
// a commercial license. Buying such a license is mandatory if you want to
20+
// modify or otherwise use the software for commercial activities involving the
21+
// Arduino software without disclosing the source code of your own applications.
22+
// To purchase a commercial license, send an email to [email protected].
23+
24+
package libraries
25+
26+
import (
27+
"testing"
28+
29+
"arduino.cc/repository/internal/libraries"
30+
"github.com/stretchr/testify/assert"
31+
"github.com/stretchr/testify/require"
32+
)
33+
34+
func TestLoadRepoListFromFile(t *testing.T) {
35+
_, err := LoadRepoListFromFile("./testdata/nonexistent.txt")
36+
assert.Error(t, err, "Attempt to load non-existent registry data file")
37+
38+
repos, err := LoadRepoListFromFile("./testdata/git_test_repos.txt")
39+
require.NoError(t, err)
40+
41+
reposAssertion := []*Repo{
42+
{
43+
URL: "https://github.com/arduino-libraries",
44+
Types: []string{"Arduino"},
45+
LibraryName: "libraries",
46+
},
47+
{
48+
URL: "[email protected]:PaulStoffregen/Audio.git",
49+
Types: []string{"Contributed"},
50+
LibraryName: "Audio",
51+
},
52+
{
53+
URL: "https://github.com/PaulStoffregen/OctoWS2811.git",
54+
Types: []string{"Arduino", "Contributed"},
55+
LibraryName: "OctoWS2811",
56+
},
57+
{
58+
URL: "https://github.com/PaulStoffregen/AltSoftSerial.git",
59+
Types: []string{"Contributed"},
60+
LibraryName: "AltSoftSerial",
61+
},
62+
{
63+
URL: "https://github.com/Cheong2K/ble-sdk-arduino.git",
64+
Types: []string{"Contributed"},
65+
LibraryName: "ble-sdk-arduino",
66+
},
67+
{
68+
URL: "https://github.com/arduino-libraries/Bridge.git",
69+
Types: []string{"Contributed"},
70+
LibraryName: "Bridge",
71+
},
72+
{
73+
URL: "https://github.com/adafruit/Adafruit_ADS1X15.git",
74+
Types: []string{"Recommended"},
75+
LibraryName: "Adafruit_ADS1X15",
76+
},
77+
{
78+
URL: "https://github.com/adafruit/Adafruit_ADXL345.git",
79+
Types: []string{"Recommended"},
80+
LibraryName: "Adafruit_ADXL345",
81+
},
82+
{
83+
URL: "https://github.com/adafruit/Adafruit_AHRS.git",
84+
Types: []string{"Recommended"},
85+
LibraryName: "Adafruit_AHRS",
86+
},
87+
{
88+
URL: "https://github.com/adafruit/Adafruit_AM2315.git",
89+
Types: []string{"Recommended"},
90+
LibraryName: "Adafruit_AM2315",
91+
},
92+
{
93+
URL: "https://github.com/arduino-libraries/Scheduler.git",
94+
Types: []string{"Arduino"},
95+
LibraryName: "Scheduler",
96+
},
97+
{
98+
URL: "https://github.com/arduino-libraries/SD.git",
99+
Types: []string{"Arduino"},
100+
LibraryName: "SD",
101+
},
102+
{
103+
URL: "https://github.com/arduino-libraries/Servo.git",
104+
Types: []string{"Arduino"},
105+
LibraryName: "Servo",
106+
},
107+
}
108+
109+
assert.Equal(t, reposAssertion, repos)
110+
}
111+
112+
func TestListRepos(t *testing.T) {
113+
repos, err := ListRepos("./testdata/git_test_repos.txt")
114+
115+
require.Equal(t, 11, len(repos))
116+
117+
require.Equal(t, "https://github.com/PaulStoffregen/OctoWS2811.git", repos[0].URL)
118+
require.Equal(t, "https://github.com/PaulStoffregen/AltSoftSerial.git", repos[1].URL)
119+
120+
require.Equal(t, "https://github.com/Cheong2K/ble-sdk-arduino.git", repos[2].URL)
121+
require.Equal(t, "https://github.com/arduino-libraries/Bridge.git", repos[3].URL)
122+
require.Equal(t, "https://github.com/adafruit/Adafruit_ADS1X15.git", repos[4].URL)
123+
require.Equal(t, "https://github.com/adafruit/Adafruit_ADXL345.git", repos[5].URL)
124+
require.Equal(t, "https://github.com/adafruit/Adafruit_AHRS.git", repos[6].URL)
125+
require.Equal(t, "https://github.com/adafruit/Adafruit_AM2315.git", repos[7].URL)
126+
require.Equal(t, "https://github.com/arduino-libraries/Scheduler.git", repos[8].URL)
127+
require.Equal(t, "https://github.com/arduino-libraries/SD.git", repos[9].URL)
128+
require.Equal(t, "https://github.com/arduino-libraries/Servo.git", repos[10].URL)
129+
require.Error(t, err)
130+
131+
error, ok := err.(libraries.GitURLsError)
132+
require.True(t, ok)
133+
require.Equal(t, "https://github.com/arduino-libraries", error.Repos[0].URL)
134+
require.Equal(t, "[email protected]:PaulStoffregen/Audio.git", error.Repos[1].URL)
135+
}

0 commit comments

Comments
 (0)