|
| 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 check |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/arduino/arduino-check/check/checkconfigurations" |
| 22 | + "github.com/arduino/arduino-check/configuration" |
| 23 | + "github.com/arduino/arduino-check/configuration/checkmode" |
| 24 | + "github.com/arduino/arduino-check/project" |
| 25 | + "github.com/arduino/arduino-check/project/projecttype" |
| 26 | + "github.com/arduino/arduino-check/util/test" |
| 27 | + "github.com/stretchr/testify/assert" |
| 28 | +) |
| 29 | + |
| 30 | +func Test_shouldRun(t *testing.T) { |
| 31 | + testTables := []struct { |
| 32 | + testName string |
| 33 | + checkProjectType projecttype.Type |
| 34 | + projectType projecttype.Type |
| 35 | + disableModes []checkmode.Type |
| 36 | + enableModes []checkmode.Type |
| 37 | + libraryManagerSetting string |
| 38 | + permissiveSetting string |
| 39 | + shouldRunAssertion assert.BoolAssertionFunc |
| 40 | + errorAssertion assert.ErrorAssertionFunc |
| 41 | + }{ |
| 42 | + {"Project type mismatch", projecttype.Library, projecttype.Sketch, []checkmode.Type{}, []checkmode.Type{}, "false", "false", assert.False, assert.NoError}, |
| 43 | + {"Disable mode match", projecttype.Library, projecttype.Library, []checkmode.Type{checkmode.LibraryManagerSubmission}, []checkmode.Type{}, "submit", "false", assert.False, assert.NoError}, |
| 44 | + {"Enable mode match", projecttype.Library, projecttype.Library, []checkmode.Type{}, []checkmode.Type{checkmode.LibraryManagerSubmission}, "submit", "false", assert.True, assert.NoError}, |
| 45 | + {"Disable mode default", projecttype.Library, projecttype.Library, []checkmode.Type{checkmode.Default}, []checkmode.Type{checkmode.LibraryManagerSubmission}, "update", "false", assert.False, assert.NoError}, |
| 46 | + {"Disable mode default override", projecttype.Library, projecttype.Library, []checkmode.Type{checkmode.Default}, []checkmode.Type{checkmode.LibraryManagerSubmission}, "submit", "false", assert.True, assert.NoError}, |
| 47 | + {"Enable mode default", projecttype.Library, projecttype.Library, []checkmode.Type{checkmode.LibraryManagerSubmission}, []checkmode.Type{checkmode.Default}, "update", "false", assert.True, assert.NoError}, |
| 48 | + {"Disable mode default override", projecttype.Library, projecttype.Library, []checkmode.Type{checkmode.LibraryManagerSubmission}, []checkmode.Type{checkmode.Default}, "submit", "false", assert.False, assert.NoError}, |
| 49 | + {"Unable to resolve", projecttype.Library, projecttype.Library, []checkmode.Type{checkmode.LibraryManagerSubmission}, []checkmode.Type{checkmode.LibraryManagerIndexed}, "false", "false", assert.False, assert.Error}, |
| 50 | + } |
| 51 | + |
| 52 | + flags := test.ConfigurationFlags() |
| 53 | + |
| 54 | + for _, testTable := range testTables { |
| 55 | + flags.Set("library-manager", testTable.libraryManagerSetting) |
| 56 | + flags.Set("permissive", testTable.permissiveSetting) |
| 57 | + |
| 58 | + configuration.Initialize(flags, []string{"/foo"}) |
| 59 | + |
| 60 | + checkConfiguration := checkconfigurations.Type{ |
| 61 | + ProjectType: testTable.checkProjectType, |
| 62 | + DisableModes: testTable.disableModes, |
| 63 | + EnableModes: testTable.enableModes, |
| 64 | + } |
| 65 | + |
| 66 | + project := project.Type{ |
| 67 | + ProjectType: testTable.projectType, |
| 68 | + } |
| 69 | + run, err := shouldRun(checkConfiguration, project) |
| 70 | + testTable.errorAssertion(t, err) |
| 71 | + if err == nil { |
| 72 | + testTable.shouldRunAssertion(t, run) |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments