Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
freeznet committed Jan 8, 2024
1 parent 16a8b21 commit 1d35a88
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions pulsar/resource_pulsar_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
},
},
})
}
1 change: 1 addition & 0 deletions pulsar/testdata/sink/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}"
Expand Down

0 comments on commit 1d35a88

Please sign in to comment.