Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
freeznet committed Dec 18, 2024
1 parent 6271760 commit 29dfaa3
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions pulsar/resource_pulsar_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func TestTopic(t *testing.T) {
{
Config: testPulsarPartitionTopic,
Check: resource.ComposeTestCheckFunc(
testPulsarTopicExists("pulsar_topic.sample-topic-1"),
testPulsarTopicExists("pulsar_topic.sample-topic-2"),
testPulsarTopicExists("pulsar_topic.sample-topic-1", t),
testPulsarTopicExists("pulsar_topic.sample-topic-2", t),
),
},
{
Config: testPulsarNonPartitionTopic,
Check: resource.ComposeTestCheckFunc(
testPulsarTopicExists("pulsar_topic.sample-topic-3"),
testPulsarTopicExists("pulsar_topic.sample-topic-4"),
testPulsarTopicExists("pulsar_topic.sample-topic-3", t),
testPulsarTopicExists("pulsar_topic.sample-topic-4", t),
),
},
},
Expand Down Expand Up @@ -117,14 +117,13 @@ func TestTopicNamespaceExternallyRemoved(t *testing.T) {
{
Config: testPulsarNamespaceWithTopic(testWebServiceURL, tName, nsName, topicName),
Check: resource.ComposeTestCheckFunc(
testPulsarTopicExists(resourceName),
testPulsarTopicExists(resourceName, t),
),
ExpectError: nil,
},
{
PreConfig: func() {
client := getClientFromMeta(testAccProvider.Meta())
t.Logf("tName: %s, nsName: %s, topicName: %s", tName, nsName, topicName)

topicName, err := utils.GetTopicName(fmt.Sprintf("persistent://%s/%s/%s", tName, nsName, topicName))
if err != nil {
t.Fatalf("ERROR_GETTING_TOPIC_NAME: %v", err)
Expand All @@ -133,19 +132,14 @@ func TestTopicNamespaceExternallyRemoved(t *testing.T) {
if err != nil {
t.Fatalf("ERROR_READ_NAMESPACE: %v", err)
}

t.Logf("topicName: %v, namespace: %s", topicName, namespace)

partitionedTopics, nonPartitionedTopics, err := client.Topics().List(*namespace)
if err != nil {
t.Fatalf("ERROR_READ_TOPIC_DATA: %v", err)
}

t.Logf("partitionedTopics: %v, nonPartitionedTopics: %v", partitionedTopics, nonPartitionedTopics)

for _, topic := range append(partitionedTopics, nonPartitionedTopics...) {
if topicName.String() == topic {
if err = client.Topics().Delete(*topicName, false, false); err != nil {
if err = client.Topics().Delete(*topicName, true, true); err != nil {
t.Fatalf("ERROR_DELETING_TEST_TOPIC: %v", err)
}
}
Expand Down Expand Up @@ -184,7 +178,7 @@ func testTopicWithPermissionGrantUpdate(t *testing.T, pnum int) {
actions = ["produce", "consume"]
}`),
Check: resource.ComposeTestCheckFunc(
testPulsarTopicExists(resourceName),
testPulsarTopicExists(resourceName, t),
resource.TestCheckResourceAttr(resourceName, "permission_grant.#", "2"),
resource.TestCheckResourceAttr(resourceName, "permission_grant.0.role", "some-role-1"),
resource.TestCheckResourceAttr(resourceName, "permission_grant.0.actions.#", "3"),
Expand All @@ -204,7 +198,7 @@ func testTopicWithPermissionGrantUpdate(t *testing.T, pnum int) {
actions = ["produce"]
}`),
Check: resource.ComposeTestCheckFunc(
testPulsarTopicExists(resourceName),
testPulsarTopicExists(resourceName, t),
resource.TestCheckResourceAttr(resourceName, "permission_grant.#", "1"),
resource.TestCheckResourceAttr(resourceName, "permission_grant.0.role", "some-role-2"),
resource.TestCheckResourceAttr(resourceName, "permission_grant.0.actions.#", "1"),
Expand Down Expand Up @@ -247,7 +241,7 @@ func testPulsarTopicDestroy(s *terraform.State) error {
return nil
}

func testPulsarTopicExists(topic string) resource.TestCheckFunc {
func testPulsarTopicExists(topic string, t *testing.T) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[topic]
if !ok {
Expand All @@ -258,6 +252,7 @@ func testPulsarTopicExists(topic string) resource.TestCheckFunc {
if err != nil {
return fmt.Errorf("ERROR_READ_TOPIC: %w", err)
}
t.Logf("topicName: %v", topicName)
namespace, err := utils.GetNameSpaceName(topicName.GetTenant(), topicName.GetNamespace())
if err != nil {
return fmt.Errorf("ERROR_READ_NAMESPACE: %w", err)
Expand Down Expand Up @@ -427,6 +422,10 @@ resource "pulsar_namespace" "test" {
topic_auto_creation {
enable = false
}
depends_on = [
pulsar_tenant.test_tenant
]
}
resource "pulsar_topic" "test" {
Expand All @@ -435,6 +434,10 @@ resource "pulsar_topic" "test" {
topic_type = "persistent"
topic_name = "%s"
partitions = 0
depends_on = [
pulsar_namespace.test
]
}
`, wsURL, tenant, ns, tenant, ns, topicName)
}

0 comments on commit 29dfaa3

Please sign in to comment.