-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds option to exempt an entire controller from checks via config file (
#350) This adds the ability to exempt a controller from all checks similar to the annotation for "exempt" which exempts all checks. I added the tests to go with this as well as for the IsActionable function.
- Loading branch information
1 parent
fa3504c
commit 0a0720a
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ main | |
|
||
*-packr.go | ||
dist | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2019 FairwindsOps Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var confExemptRuleTest = ` | ||
checks: | ||
ANY: warning | ||
OTHER: warning | ||
exemptions: | ||
- controllerNames: | ||
- test | ||
rules: | ||
- ANY | ||
` | ||
|
||
var confExemptTest = ` | ||
checks: | ||
ANY: warning | ||
exemptions: | ||
- controllerNames: | ||
- test | ||
` | ||
|
||
func TestInclusiveExemption(t *testing.T) { | ||
parsedConf, _ := Parse([]byte(confExemptTest)) | ||
applicable := parsedConf.IsActionable("ANY", "test") | ||
applicableOtherController := parsedConf.IsActionable("ANY", "other") | ||
|
||
assert.False(t, applicable, "Expected all checks to be exempted when their controller is specified.") | ||
assert.True(t, applicableOtherController, "Expected checks to only be exempted when their controller is specified.") | ||
} | ||
|
||
func TestIndividualRuleException(t *testing.T) { | ||
parsedConf, _ := Parse([]byte(confExemptRuleTest)) | ||
applicable := parsedConf.IsActionable("ANY", "test") | ||
applicableOtherRule := parsedConf.IsActionable("OTHER", "test") | ||
applicableOtherRuleOtherController := parsedConf.IsActionable("OTHER", "other") | ||
applicableRuleOtherController := parsedConf.IsActionable("ANY", "other") | ||
|
||
assert.False(t, applicable, "Expected all checks to be exempted when their controller and rule are specified.") | ||
assert.True(t, applicableOtherRule, "Expected checks to only be exempted when their controller and rule are specified.") | ||
assert.True(t, applicableOtherRuleOtherController, "Expected checks to only be exempted when their controller and rule are specified.") | ||
assert.True(t, applicableRuleOtherController, "Expected checks to only be exempted when their controller and rule are specified.") | ||
} |