forked from trufflesecurity/trufflehog
-
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 missing pagination on github calls (trufflesecurity#30)
* 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>
- Loading branch information
1 parent
6b18342
commit 1fb7672
Showing
5 changed files
with
245 additions
and
92 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
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,19 @@ | ||
package common | ||
|
||
func AddStringSliceItem(item string, slice *[]string) { | ||
for _, i := range *slice { | ||
if i == item { | ||
return | ||
} | ||
} | ||
*slice = append(*slice, item) | ||
} | ||
|
||
func RemoveStringSliceItem(item string, slice *[]string) { | ||
for i, listItem := range *slice { | ||
if item == listItem { | ||
(*slice)[i] = (*slice)[len(*slice)-1] | ||
*slice = (*slice)[:len(*slice)-1] | ||
} | ||
} | ||
} |
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,76 @@ | ||
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) | ||
} | ||
} | ||
} |
Oops, something went wrong.