Skip to content

Commit

Permalink
feat: add kafkaInstanceState scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Gezi-lzq committed Aug 7, 2024
1 parent 0430379 commit c92aee5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions internal/provider/automq_kafka_instance_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,24 @@ func TestAccKafkaInstanceResource(t *testing.T) {
WillReturnResponse(wiremock.NewResponse().WithBody(string(creatingResponseJson)).WithStatus(http.StatusOK))
_ = wiremockClient.StubFor(createInstanceStub)

getInstanceStubOnStarted := wiremock.Get(wiremock.
getInstanceStubWhenStarted := wiremock.Get(wiremock.
URLPathEqualTo(fmt.Sprintf(getKafkaInstancePath, creatingResponse.InstanceID))).
InScenario("Started").WillSetStateTo("Deleted").
WillReturnResponse(wiremock.NewResponse().WithBody(string(availableResponseJson)).WithStatus(http.StatusOK))
_ = wiremockClient.StubFor(getInstanceStubOnStarted)

getInstanceStubOnDeleted := wiremock.Get(wiremock.
URLPathEqualTo(fmt.Sprintf(getKafkaInstancePath, creatingResponse.InstanceID))).
InScenario("Deleted").
WillReturnResponse(wiremock.NewResponse().WithBody(string(availableResponseJson)).WithStatus(http.StatusOK))
_ = wiremockClient.StubFor(getInstanceStubOnDeleted)
WillReturnResponse(wiremock.NewResponse().WithBody(string(availableResponseJson)).WithStatus(http.StatusOK)).
InScenario("KafkaInstanceState").WhenScenarioStateIs(wiremock.ScenarioStateStarted)
_ = wiremockClient.StubFor(getInstanceStubWhenStarted)

deleteInstanceStub := wiremock.Delete(wiremock.
URLPathEqualTo(fmt.Sprintf(getKafkaInstancePath, creatingResponse.InstanceID))).
WillReturnResponse(wiremock.NewResponse().WithBody(string(deletingResponseJson)).WithStatus(http.StatusOK))
WillReturnResponse(wiremock.NewResponse().WithBody(string(deletingResponseJson)).WithStatus(http.StatusNoContent)).
InScenario("KafkaInstanceState").WillSetStateTo("Deleted")
_ = wiremockClient.StubFor(deleteInstanceStub)

getInstanceStubWhenDeleted := wiremock.Get(wiremock.
URLPathEqualTo(fmt.Sprintf(getKafkaInstancePath, creatingResponse.InstanceID))).
WillReturnResponse(wiremock.NewResponse().WithStatus(http.StatusNotFound)).
InScenario("KafkaInstanceState").WhenScenarioStateIs("Deleted")
_ = wiremockClient.StubFor(getInstanceStubWhenDeleted)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Expand All @@ -86,8 +87,6 @@ func TestAccKafkaInstanceResource(t *testing.T) {
})

checkStubCount(t, wiremockClient, createInstanceStub, fmt.Sprintf("POST %s", createKafkaInstancePath), expectedCountOne)
checkStubCount(t, wiremockClient, getInstanceStubOnStarted, fmt.Sprintf("GET %s", getKafkaInstancePath), expectedCountOne)
checkStubCount(t, wiremockClient, getInstanceStubOnDeleted, fmt.Sprintf("GET %s", getKafkaInstancePath), expectedCountOne)
checkStubCount(t, wiremockClient, deleteInstanceStub, fmt.Sprintf("DELETE %s", getKafkaInstancePath), expectedCountOne)
}

Expand Down

0 comments on commit c92aee5

Please sign in to comment.