-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathlogs_test.go
More file actions
82 lines (78 loc) · 2.16 KB
/
logs_test.go
File metadata and controls
82 lines (78 loc) · 2.16 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
70
71
72
73
74
75
76
77
78
79
80
81
82
package logs
import (
"fmt"
"net/http"
"regexp"
"testing"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil"
)
func TestLogsInstanceSavesIDsOnError(t *testing.T) {
projectId := uuid.NewString()
instanceId := uuid.NewString()
const (
region = "eu01"
)
s := testutil.NewMockServer(t)
defer s.Server.Close()
tfConfig := fmt.Sprintf(`
provider "stackit" {
default_region = "%s"
logs_custom_endpoint = "%s"
service_account_token = "mock-server-needs-no-auth"
}
resource "stackit_logs_instance" "logs" {
project_id = "%s"
display_name = "logs-instance-example"
retention_days = 30
}
`, region, s.Server.URL, projectId)
resource.UnitTest(t, resource.TestCase{
ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
PreConfig: func() {
s.Reset(
testutil.MockResponse{
Description: "create instance",
ToJsonBody: logs.LogsInstance{
Id: instanceId,
},
},
testutil.MockResponse{
Description: "failing waiter",
StatusCode: http.StatusInternalServerError,
},
)
},
Config: tfConfig,
ExpectError: regexp.MustCompile("Error creating Logs Instance.*"),
},
{
PreConfig: func() {
s.Reset(
testutil.MockResponse{
Description: "refresh",
Handler: func(w http.ResponseWriter, req *http.Request) {
expected := fmt.Sprintf("/v1/projects/%s/regions/%s/instances/%s", projectId, region, instanceId)
if req.URL.Path != expected {
t.Errorf("expected request to %s, got %s", expected, req.URL.Path)
}
w.WriteHeader(http.StatusInternalServerError)
},
},
testutil.MockResponse{Description: "delete", StatusCode: http.StatusAccepted},
testutil.MockResponse{
Description: "delete waiter",
StatusCode: http.StatusNotFound,
},
)
},
RefreshState: true,
ExpectError: regexp.MustCompile("Error reading logs instance.*"),
},
},
})
}