-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_test.go
66 lines (56 loc) · 1.58 KB
/
provider_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
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
log "github.com/sirupsen/logrus"
)
var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider
func init() {
testAccProvider = Provider()
testAccProviders = map[string]terraform.ResourceProvider{
"threatstack": testAccProvider,
}
}
func TestProvider(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProviderImpl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}
func testAccPreCheck(test *testing.T) {
if v := os.Getenv("THREATSTACK_API_KEY"); v == "" {
test.Fatal("THREATSTACK_API_KEY must be set for acceptance tests")
}
if v := os.Getenv("THREATSTACK_ORG_ID"); v == "" {
test.Fatal("THREATSTACK_ORG_ID must be set for acceptance tests")
}
if v := os.Getenv("THREATSTACK_USER_ID"); v == "" {
test.Fatal("THREATSTACK_USER_ID must be set for acceptance tests")
}
}
func sweepRulesets(region string) error {
client, err := sharedClient()
if err != nil {
return err
}
rulesets, err := client.Rulesets.List()
if err != nil {
return fmt.Errorf("Error listing rulesets: %s", err.Error())
}
for _, ruleset := range rulesets {
if strings.HasPrefix(ruleset.Name, "tf") {
err := client.Rulesets.Delete(ruleset.ID)
if err != nil {
log.Errorf("Error deleting ruleset %s: %s", ruleset.Name, err.Error())
}
}
}
return nil
}