forked from trek10inc/awsets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
supportedresources_test.go
59 lines (52 loc) · 1.56 KB
/
supportedresources_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package awsets
import (
"bufio"
"fmt"
"os"
"testing"
"github.com/trek10inc/awsets/resource"
)
// Tests to make sure the documentation is up to date with the current list of supported resource types
func Test_SupportResources(t *testing.T) {
// Read documented list of resource types
f, err := os.Open("supported_resources.txt")
if err != nil {
t.Fatalf("failed to load file: %v", err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)
// Build map of types
supported := make(map[resource.ResourceType]struct{})
for scanner.Scan() {
supported[resource.ResourceType(scanner.Text())] = struct{}{}
}
// Iterate through resource types supported in code. For each. check if it is in the documentation
// If it is, remove it
// If it isn't, append it to a list of resources that need added
needsAdded := make([]resource.ResourceType, 0)
for _, at := range Types(nil, nil) {
_, exists := supported[at]
if exists {
delete(supported, at)
} else {
needsAdded = append(needsAdded, at)
}
}
// If resources are missing from documentation, fail test & print them
if len(needsAdded) > 0 {
fmt.Printf("The following resource types need added to supported_types.txt:\n")
for _, v := range needsAdded {
fmt.Printf("%s\n", v)
}
t.Fail()
}
// If resources are in documentation that are NOT supported in code, fail test and print them
if len(supported) > 0 {
fmt.Printf("The following resource types need removed from supported_types.txt:\n")
for _, v := range supported {
fmt.Printf("%s\n", v)
}
t.Fail()
}
}