mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
1fb767247f
* Add missing pagination on github calls Includes some refactoring to improve readability and code reuse. * Close response body and handle rate limit * Re-include support for including users as repos to github scans * Fix gist test to match new func signature * Add current test name to logging * Support username as org use case * Also include no-auth user as org Co-authored-by: Bill Rich <bill.rich@trufflesec.com>
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package common
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestAddItem(t *testing.T) {
|
|
type Case struct {
|
|
Slice []string
|
|
Modifier []string
|
|
Expected []string
|
|
}
|
|
tests := map[string]Case{
|
|
"newItem": {
|
|
Slice: []string{"a", "b", "c"},
|
|
Modifier: []string{"d"},
|
|
Expected: []string{"a", "b", "c", "d"},
|
|
},
|
|
"newDuplicate": {
|
|
Slice: []string{"a", "b", "c"},
|
|
Modifier: []string{"c"},
|
|
Expected: []string{"a", "b", "c"},
|
|
},
|
|
}
|
|
|
|
for name, test := range tests {
|
|
for _, item := range test.Modifier {
|
|
AddStringSliceItem(item, &test.Slice)
|
|
}
|
|
|
|
if !reflect.DeepEqual(test.Slice, test.Expected) {
|
|
t.Errorf("%s: expected:%v, got:%v", name, test.Expected, test.Slice)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRemoveItem(t *testing.T) {
|
|
type Case struct {
|
|
Slice []string
|
|
Modifier []string
|
|
Expected []string
|
|
}
|
|
tests := map[string]Case{
|
|
"existingItemEnd": {
|
|
Slice: []string{"a", "b", "c"},
|
|
Modifier: []string{"c"},
|
|
Expected: []string{"a", "b"},
|
|
},
|
|
"existingItemMiddle": {
|
|
Slice: []string{"a", "b", "c"},
|
|
Modifier: []string{"b"},
|
|
Expected: []string{"a", "c"},
|
|
},
|
|
"existingItemBeginning": {
|
|
Slice: []string{"a", "b", "c"},
|
|
Modifier: []string{"a"},
|
|
Expected: []string{"c", "b"},
|
|
},
|
|
"nonExistingItem": {
|
|
Slice: []string{"a", "b", "c"},
|
|
Modifier: []string{"d"},
|
|
Expected: []string{"a", "b", "c"},
|
|
},
|
|
}
|
|
|
|
for name, test := range tests {
|
|
for _, item := range test.Modifier {
|
|
RemoveStringSliceItem(item, &test.Slice)
|
|
}
|
|
|
|
if !reflect.DeepEqual(test.Slice, test.Expected) {
|
|
t.Errorf("%s: expected:%v, got:%v", name, test.Expected, test.Slice)
|
|
}
|
|
}
|
|
}
|