-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rbac role and process finalizers
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
- Loading branch information
1 parent
78aa4af
commit 9d4cfa1
Showing
7 changed files
with
123 additions
and
34 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 |
---|---|---|
|
@@ -31,6 +31,7 @@ rules: | |
verbs: | ||
- get | ||
- list | ||
- patch | ||
- update | ||
- watch | ||
- apiGroups: | ||
|
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
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
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,29 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package slice | ||
|
||
// ContainsString checks if a given slice of strings contains the provided string. | ||
func ContainsString(slice []string, s string) bool { | ||
for _, item := range slice { | ||
if item == s { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// RemoveString returns a newly created []string that contains all items from slice that | ||
// are not equal to s. | ||
func RemoveString(slice []string, s string) []string { | ||
var newSlice []string | ||
for _, item := range slice { | ||
if item == s { | ||
continue | ||
} | ||
newSlice = append(newSlice, item) | ||
} | ||
return newSlice | ||
} |
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,63 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package slice | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestContainsString(t *testing.T) { | ||
src := []string{"aa", "bb", "cc"} | ||
|
||
if !ContainsString(src, "bb") { | ||
t.Errorf("ContainsString didn't find the string as expected") | ||
} | ||
|
||
src = make([]string, 0) | ||
if ContainsString(src, "") { | ||
t.Errorf("The result returned is not the expected result") | ||
} | ||
} | ||
|
||
func TestRemoveString(t *testing.T) { | ||
tests := []struct { | ||
testName string | ||
input []string | ||
remove string | ||
want []string | ||
}{ | ||
{ | ||
testName: "Nil input slice", | ||
input: nil, | ||
remove: "", | ||
want: nil, | ||
}, | ||
{ | ||
testName: "Remove a string from input slice", | ||
input: []string{"a", "ab", "cdef"}, | ||
remove: "ab", | ||
want: []string{"a", "cdef"}, | ||
}, | ||
{ | ||
testName: "Slice doesn't contain the string", | ||
input: []string{"a", "ab", "cdef"}, | ||
remove: "NotPresentInSlice", | ||
want: []string{"a", "ab", "cdef"}, | ||
}, | ||
{ | ||
testName: "All strings removed, result is nil", | ||
input: []string{"a"}, | ||
remove: "a", | ||
want: nil, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
if got := RemoveString(tt.input, tt.remove); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("%v: RemoveString(%v, %q) = %v WANT %v", tt.testName, tt.input, tt.remove, got, tt.want) | ||
} | ||
} | ||
} |