-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathdns_test.go
More file actions
69 lines (64 loc) · 1.65 KB
/
dns_test.go
File metadata and controls
69 lines (64 loc) · 1.65 KB
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
67
68
69
package dns
import (
"fmt"
"net/http"
"regexp"
"testing"
"time"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil"
)
func TestCreateTimeout(t *testing.T) {
// only tests create timeout, read/update/delete would need a successful create beforehand. We could do this, but
// these tests would be slow and flaky
projectID := uuid.NewString()
s := testutil.NewMockServer(t)
defer s.Server.Close()
providerConfig := fmt.Sprintf(`
provider "stackit" {
default_region = "eu01"
dns_custom_endpoint = "%s"
service_account_token = "mock-server-needs-no-auth"
}
`, s.Server.URL)
zoneResource := fmt.Sprintf(`
variable "name" {}
resource "stackit_dns_zone" "zone" {
project_id = "%s"
name = var.name
dns_name = "dns.example.com"
timeouts = {
create = "10ms"
read = "10ms"
update = "10ms"
delete = "10ms"
}
}
`, projectID)
resource.UnitTest(t, resource.TestCase{
ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
// create fails
PreConfig: func() {
s.Reset(testutil.MockResponse{
Handler: func(_ http.ResponseWriter, r *http.Request) {
ctx := r.Context()
select {
case <-ctx.Done():
case <-time.After(20 * time.Millisecond):
}
},
})
},
Config: providerConfig + "\n" + zoneResource,
ExpectError: regexp.MustCompile("deadline exceeded"),
ConfigVariables: config.Variables{
"name": config.StringVariable("create-zone"),
},
},
},
})
}