From 1d35a885929bf1db50581da4766a06f0e867bb39 Mon Sep 17 00:00:00 2001 From: Rui Fu Date: Mon, 8 Jan 2024 22:37:31 +0800 Subject: [PATCH] add test --- pulsar/resource_pulsar_sink_test.go | 69 +++++++++++++++++++++++++++++ pulsar/testdata/sink/main.tf | 1 + 2 files changed, 70 insertions(+) diff --git a/pulsar/resource_pulsar_sink_test.go b/pulsar/resource_pulsar_sink_test.go index 1f94fd7..78cd321 100644 --- a/pulsar/resource_pulsar_sink_test.go +++ b/pulsar/resource_pulsar_sink_test.go @@ -237,3 +237,72 @@ resource "pulsar_sink" "test" { } `, name, testdataArchive) } + +func TestSinkUpdate(t *testing.T) { + configBytes, err := ioutil.ReadFile("testdata/sink/main.tf") + if err != nil { + t.Fatal(err) + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckWithAPIVersion(t, config.V3) }, + ProviderFactories: testAccProviderFactories, + PreventPostDestroyRefresh: false, + CheckDestroy: testPulsarSinkDestroy, + Steps: []resource.TestStep{ + { + Config: string(configBytes), + Check: resource.ComposeTestCheckFunc(func(s *terraform.State) error { + name := "pulsar_sink.sink-1" + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("%s not be found", name) + } + + client := getClientFromMeta(testAccProvider.Meta()).Sinks() + + parts := strings.Split(rs.Primary.ID, "/") + if len(parts) != 3 { + return errors.New("resource id should be tenant/namespace/name format") + } + + _, err := client.GetSink(parts[0], parts[1], parts[2]) + if err != nil { + return err + } + + return nil + }), + }, + { + Config: string(configBytes), + PlanOnly: true, + ExpectNonEmptyPlan: true, + }, + { + Config: string(configBytes), + Check: resource.ComposeTestCheckFunc(func(s *terraform.State) error { + name := "pulsar_sink.sink-1" + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("%s not be found", name) + } + + client := getClientFromMeta(testAccProvider.Meta()).Sinks() + + parts := strings.Split(rs.Primary.ID, "/") + if len(parts) != 3 { + return errors.New("resource id should be tenant/namespace/name format") + } + + _, err := client.GetSink(parts[0], parts[1], parts[2]) + if err != nil { + return err + } + + return nil + }), + }, + }, + }) +} diff --git a/pulsar/testdata/sink/main.tf b/pulsar/testdata/sink/main.tf index e5ed563..685e6b9 100644 --- a/pulsar/testdata/sink/main.tf +++ b/pulsar/testdata/sink/main.tf @@ -33,6 +33,7 @@ resource "pulsar_sink" "sink-1" { auto_ack = true processing_guarantees = "EFFECTIVELY_ONCE" + retain_ordering = false archive = "https://www.apache.org/dyn/mirrors/mirrors.cgi?action=download&filename=pulsar/pulsar-2.10.4/connectors/pulsar-io-jdbc-postgres-2.10.4.nar" configs = "{\"jdbcUrl\":\"jdbc:postgresql://localhost:5432/pulsar_postgres_jdbc_sink\",\"password\":\"password\",\"tableName\":\"pulsar_postgres_jdbc_sink\",\"userName\":\"postgres\"}"