Skip to content

Commit e8e0311

Browse files
committed
fix test
1 parent cc83828 commit e8e0311

File tree

2 files changed

+1708
-1650
lines changed

2 files changed

+1708
-1650
lines changed

internal/services/instance/action_server_action_test.go

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package instance_test
22

33
import (
4+
"fmt"
45
"regexp"
6+
"strconv"
57
"testing"
68

79
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-testing/terraform"
811
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
912
)
1013

@@ -13,7 +16,6 @@ func TestAccActionServer_Basic(t *testing.T) {
1316
defer tt.Cleanup()
1417

1518
resource.ParallelTest(t, resource.TestCase{
16-
PreCheck: func() { acctest.PreCheck(t) },
1719
ProtoV6ProviderFactories: tt.ProviderFactories,
1820
Steps: []resource.TestStep{
1921
{
@@ -36,8 +38,54 @@ func TestAccActionServer_Basic(t *testing.T) {
3638
action = "reboot"
3739
server_id = scaleway_instance_server.main.id
3840
}
41+
}`,
42+
},
43+
{
44+
Config: `
45+
resource "scaleway_instance_server" "main" {
46+
name = "test-terraform-datasource-private-nic"
47+
type = "DEV1-S"
48+
image = "ubuntu_jammy"
49+
50+
lifecycle {
51+
action_trigger {
52+
events = [after_create]
53+
actions = [action.scaleway_instance_server_action.main]
54+
}
55+
}
3956
}
40-
`,
57+
58+
action "scaleway_instance_server_action" "main" {
59+
config {
60+
action = "reboot"
61+
server_id = scaleway_instance_server.main.id
62+
}
63+
}
64+
65+
data "scaleway_audit_trail_event" "instance" {
66+
resource_type = "instance_server"
67+
resource_id = scaleway_instance_server.main.id
68+
method_name = "ServerAction"
69+
}`,
70+
Check: resource.ComposeTestCheckFunc(
71+
resource.TestCheckResourceAttrSet("data.scaleway_audit_trail_event.instance", "events.#"),
72+
func(state *terraform.State) error {
73+
rs, ok := state.RootModule().Resources["data.scaleway_audit_trail_event.instance"]
74+
if !ok {
75+
return fmt.Errorf("not found: data.scaleway_audit_trail_event.instance")
76+
}
77+
countStr := rs.Primary.Attributes["events.#"]
78+
count, err := strconv.Atoi(countStr)
79+
if err != nil {
80+
return fmt.Errorf("could not parse events.# as integer: %v", err)
81+
}
82+
if count < 1 {
83+
return fmt.Errorf("expected events count > 1, got %d", count)
84+
}
85+
86+
return nil
87+
},
88+
),
4189
},
4290
},
4391
})
@@ -48,7 +96,6 @@ func TestAccActionServer_UnknownVerb(t *testing.T) {
4896
defer tt.Cleanup()
4997

5098
resource.ParallelTest(t, resource.TestCase{
51-
PreCheck: func() { acctest.PreCheck(t) },
5299
ProtoV6ProviderFactories: tt.ProviderFactories,
53100
Steps: []resource.TestStep{
54101
{

0 commit comments

Comments
 (0)