Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 73a856c

Browse files
author
Jeff Carter
committed
add github action for testing
add test around failure that led to v0.1.1
1 parent ec27b76 commit 73a856c

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

.github/workflows/test.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on: [push, pull_request]
2+
name: Test
3+
jobs:
4+
test:
5+
strategy:
6+
matrix:
7+
go-version: [1.14.x, 1.15.x]
8+
os: [ubuntu-latest, macos-latest, windows-latest]
9+
runs-on: ${{ matrix.os }}
10+
steps:
11+
- name: Install Go
12+
uses: actions/setup-go@v2
13+
with:
14+
go-version: ${{ matrix.go-version }}
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
- name: Test
18+
run: go test ./...

main.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,26 @@ func Listers(include []string, exclude []string) []ListerName {
9595
return ret
9696
}
9797

98-
func GetByName(name ListerName) lister.Lister {
98+
func GetByName(name ListerName) (lister.Lister, error) {
9999

100100
for _, v := range lister.AllListers() {
101101
if name == ListerName(reflect.TypeOf(v).Name()) {
102-
return v
102+
return v, nil
103103
}
104104
}
105-
panic(fmt.Errorf("no lister found for %s", name))
105+
return nil, fmt.Errorf("no lister found for %s", name)
106106
}
107107

108-
func GetByType(kind resource.ResourceType) lister.Lister {
108+
func GetByType(kind resource.ResourceType) (lister.Lister, error) {
109109

110110
for _, v := range lister.AllListers() {
111111
for _, t := range v.Types() {
112112
if t == kind {
113-
return v
113+
return v, nil
114114
}
115115
}
116116
}
117-
panic(fmt.Errorf("no lister found for %s", kind))
117+
return nil, fmt.Errorf("no lister found for %s", kind)
118118
}
119119

120120
func Regions(prefixes ...string) ([]string, error) {
@@ -197,9 +197,13 @@ func List(ctx context2.AWSetsCtx, regions []string, listers []ListerName, cache
197197
rg.Merge(group)
198198
} else {
199199
ctx.Logger.Infof("%d: not cached: %s - %s\n", id, job.region, job.lister)
200-
idx := GetByName(job.lister)
200+
lister, err := GetByName(job.lister)
201+
if err != nil {
202+
ctx.Logger.Errorf("failed to get lister by name: %v", err)
203+
continue
204+
}
201205
ctxcp := ctx.Copy(job.region)
202-
group, err := idx.List(ctxcp)
206+
group, err := lister.List(ctxcp)
203207
if err != nil {
204208
// indicates service is not supported in a region, likely a better way to do this though
205209
// eks returns "AccessDenied" if the service isn't in the region though

main_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package awspelunk
2+
3+
import (
4+
"strings"
5+
"testing"
6+
)
7+
8+
func Test_Types(t *testing.T) {
9+
types := Types([]string{""}, []string{""})
10+
if len(types) == 0 {
11+
t.Fatalf("expected all types")
12+
}
13+
types = Types(nil, nil)
14+
if len(types) == 0 {
15+
t.Fatalf("expected all types")
16+
}
17+
types = Types([]string{""}, []string{"ec2"})
18+
for _, rt := range types {
19+
if strings.HasPrefix(rt.String(), "ec2") {
20+
t.Fatalf("expected ec2* resource types to have been filtered out")
21+
}
22+
}
23+
types = Types([]string{"ec2"}, []string{""})
24+
for _, rt := range types {
25+
if !strings.HasPrefix(rt.String(), "ec2") {
26+
t.Fatalf("on expected ec2* resource types to be present")
27+
}
28+
}
29+
}
30+
31+
func Test_Listers(t *testing.T) {
32+
listers := Listers([]string{""}, []string{""})
33+
if len(listers) == 0 {
34+
t.Fatalf("expected all listers")
35+
}
36+
listers = Listers(nil, nil)
37+
if len(listers) == 0 {
38+
t.Fatalf("expected all listers")
39+
}
40+
}

0 commit comments

Comments
 (0)