|
| 1 | +// This file is part of arduino-check. |
| 2 | +// |
| 3 | +// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This software is released under the GNU General Public License version 3, |
| 6 | +// which covers the main part of arduino-check. |
| 7 | +// The terms of this license can be found at: |
| 8 | +// https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | +// |
| 10 | +// You can be released from the requirements of the above licenses by purchasing |
| 11 | +// a commercial license. Buying such a license is mandatory if you want to |
| 12 | +// modify or otherwise use the software for commercial activities involving the |
| 13 | +// Arduino software without disclosing the source code of your own applications. |
| 14 | +// To purchase a commercial license, send an email to [email protected]. |
| 15 | + |
| 16 | +package packageindex |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/arduino/go-paths-helper" |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | +) |
| 24 | + |
| 25 | +func TestHasValidExtension(t *testing.T) { |
| 26 | + assert.True(t, HasValidExtension(paths.New("/foo", "bar.json"))) |
| 27 | + assert.False(t, HasValidExtension(paths.New("/foo", "bar.baz"))) |
| 28 | +} |
| 29 | + |
| 30 | +func TestHasValidFilename(t *testing.T) { |
| 31 | + testTables := []struct { |
| 32 | + testName string |
| 33 | + filename string |
| 34 | + officialCheckMode bool |
| 35 | + assertion assert.BoolAssertionFunc |
| 36 | + }{ |
| 37 | + {"Official, primary", "package_index.json", true, assert.True}, |
| 38 | + {"Official, secondary", "package_foo_index.json", true, assert.True}, |
| 39 | + {"Official, invalid", "packageindex.json", true, assert.False}, |
| 40 | + {"Unofficial, valid", "package_foo_index.json", false, assert.True}, |
| 41 | + {"Unofficial, official", "package_index.json", false, assert.False}, |
| 42 | + {"Unofficial, invalid", "packageindex.json", false, assert.False}, |
| 43 | + } |
| 44 | + |
| 45 | + for _, testTable := range testTables { |
| 46 | + testTable.assertion(t, HasValidFilename(paths.New("/foo", testTable.filename), testTable.officialCheckMode), testTable.testName) |
| 47 | + } |
| 48 | +} |
0 commit comments