|
| 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