Skip to content

Commit e6fed30

Browse files
committed
Export libraries.loadRepoListFromFile()
Access to this function from outside the package is needed for validating the registry data file.
1 parent 7f69ac5 commit e6fed30

File tree

2 files changed

+83
-3
lines changed

2 files changed

+83
-3
lines changed

internal/libraries/repolist.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import (
3333
"strings"
3434
)
3535

36-
func loadRepoListFromFile(filename string) ([]*Repo, error) {
36+
// LoadRepoListFromFile returns an unfiltered list of library registry entries loaded from the given data file.
37+
func LoadRepoListFromFile(filename string) ([]*Repo, error) {
3738
file, err := os.Open(filename)
3839
if err != nil {
3940
return nil, err
@@ -153,9 +154,9 @@ func toListOfUniqueRepos(repos []*Repo) []*Repo {
153154
return finalRepos
154155
}
155156

156-
// ListRepos loads a list from the given filename.
157+
// ListRepos returns a filtered list of library registry entries loaded from the given data file.
157158
func ListRepos(reposFilename string) ([]*Repo, error) {
158-
repos, err := loadRepoListFromFile(reposFilename)
159+
repos, err := LoadRepoListFromFile(reposFilename)
159160
if err != nil {
160161
return nil, err
161162
}

internal/libraries/repolist_test.go

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

29+
"github.com/stretchr/testify/assert"
2930
"github.com/stretchr/testify/require"
3031
)
3132

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+
32111
func TestListRepos(t *testing.T) {
33112
repos, err := ListRepos("./testdata/git_test_repos.txt")
34113

0 commit comments

Comments
 (0)