|
| 1 | +// This file is part of libraries-repository-engine. |
| 2 | +// |
| 3 | +// Copyright 2025 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 license@arduino.cc. |
| 23 | + |
| 24 | +package checkregistry |
| 25 | + |
| 26 | +import ( |
| 27 | + "path/filepath" |
| 28 | + "testing" |
| 29 | + |
| 30 | + "github.com/stretchr/testify/require" |
| 31 | +) |
| 32 | + |
| 33 | +func TestRegistryValidation(t *testing.T) { |
| 34 | + type testcase struct { |
| 35 | + Name string |
| 36 | + TestFile string |
| 37 | + ExpectedResult string |
| 38 | + } |
| 39 | + tests := []testcase{ |
| 40 | + {"EmptyArg", "", "registry data file argument testdata is a folder, not a file"}, |
| 41 | + {"NonExistentFile", "nonexistent.txt", "while loading registry data file: stat testdata/nonexistent.txt: no such file or directory"}, |
| 42 | + //{"InvalidDataFormat", "invalid-data-format.txt", "while loading registry data file: invalid line format (3 fields are required): https://github.com/arduino-libraries/SD.git|Partner;SD"}, |
| 43 | + {"InvalidUrlFormat", "invalid-url-format.txt", "while filtering registry data file: Following URL are unknown or unsupported git repos:\nhttps://github.com/arduino-libraries/SD\n"}, |
| 44 | + {"MissingType", "no-type.txt", "invalid type '' used by library 'SD'"}, |
| 45 | + {"InvalidType", "invalid-type.txt", "invalid type 'foo' used by library 'SD'"}, |
| 46 | + {"DuplicateRepoURL", "duplicate-url.txt", "registry data file contains duplicate URLs"}, |
| 47 | + {"DuplicateLibName", "duplicate-name.txt", "registry data file contains duplicates of name 'SD'"}, |
| 48 | + {"ValidList", "valid.txt", ""}, |
| 49 | + } |
| 50 | + for _, test := range tests { |
| 51 | + t.Run(test.Name, func(t *testing.T) { |
| 52 | + err := runcheck(filepath.Join("testdata", test.TestFile)) |
| 53 | + if test.ExpectedResult == "" { |
| 54 | + require.NoError(t, err) |
| 55 | + } else { |
| 56 | + require.EqualError(t, err, test.ExpectedResult) |
| 57 | + } |
| 58 | + }) |
| 59 | + } |
| 60 | +} |
0 commit comments