-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tagging logic. Allows syncing creds only on certain targets
- Loading branch information
Julien Duchesne
committed
Jun 12, 2019
1 parent
4c0834a
commit 301f71c
Showing
5 changed files
with
195 additions
and
1 deletion.
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
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,141 @@ | ||
package credentials | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestShouldSyncCredentials(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
name string | ||
wantedTargetTags targetTagsMatcher | ||
targetTags map[string]string | ||
expected bool | ||
}{ | ||
{ | ||
name: "No tags", | ||
wantedTargetTags: targetTagsMatcher{ | ||
DoMatch: map[string]interface{}{}, | ||
DontMatch: map[string]interface{}{}, | ||
}, | ||
targetTags: map[string]string{}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "No filter", | ||
wantedTargetTags: targetTagsMatcher{ | ||
DoMatch: map[string]interface{}{}, | ||
DontMatch: map[string]interface{}{}, | ||
}, | ||
targetTags: map[string]string{ | ||
"MyTag": "MyValue", | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "Match", | ||
wantedTargetTags: targetTagsMatcher{ | ||
DoMatch: map[string]interface{}{ | ||
"MyFirstTag": "MyValue", | ||
"MyTag": "MyValue", | ||
}, | ||
DontMatch: map[string]interface{}{}, | ||
}, | ||
targetTags: map[string]string{ | ||
"MyTag": "MyValue", | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "Match List Item", | ||
wantedTargetTags: targetTagsMatcher{ | ||
DoMatch: map[string]interface{}{ | ||
"MyTag": []string{"FirstValue", "MyValue"}, | ||
}, | ||
DontMatch: map[string]interface{}{}, | ||
}, | ||
targetTags: map[string]string{ | ||
"MyTag": "MyValue", | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "List Without Matches", | ||
wantedTargetTags: targetTagsMatcher{ | ||
DoMatch: map[string]interface{}{ | ||
"MyTag": []string{"FirstValue", "SecondValue"}, | ||
}, | ||
DontMatch: map[string]interface{}{}, | ||
}, | ||
targetTags: map[string]string{ | ||
"MyTag": "MyValue", | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "String Doesnt Match", | ||
wantedTargetTags: targetTagsMatcher{ | ||
DoMatch: map[string]interface{}{ | ||
"MyTag": "AValue", | ||
}, | ||
DontMatch: map[string]interface{}{}, | ||
}, | ||
targetTags: map[string]string{ | ||
"MyTag": "MyValue", | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "String that shouldn't match", | ||
wantedTargetTags: targetTagsMatcher{ | ||
DoMatch: map[string]interface{}{}, | ||
DontMatch: map[string]interface{}{ | ||
"MyTag": "MyValue", | ||
}, | ||
}, | ||
targetTags: map[string]string{ | ||
"MyTag": "MyValue", | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "String in list that shouldn't match", | ||
wantedTargetTags: targetTagsMatcher{ | ||
DoMatch: map[string]interface{}{}, | ||
DontMatch: map[string]interface{}{ | ||
"MyTag": []string{"Test", "MyValue"}, | ||
}, | ||
}, | ||
targetTags: map[string]string{ | ||
"MyTag": "MyValue", | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "Match and exclude", | ||
wantedTargetTags: targetTagsMatcher{ | ||
DoMatch: map[string]interface{}{ | ||
"MyTag": "Value", | ||
}, | ||
DontMatch: map[string]interface{}{ | ||
"MyOtherTag": []string{"Test", "MyValue"}, | ||
}, | ||
}, | ||
targetTags: map[string]string{ | ||
"MyTag": "Value", | ||
"MyOtherTag": "MyValue", | ||
}, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, tt := range cases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
credentials := &Base{TargetTags: tt.wantedTargetTags} | ||
assert.Equal(t, tt.expected, credentials.ShouldSync(tt.targetTags)) | ||
}) | ||
} | ||
} |
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