From bb27deab3113d3bbfe235e59a72d66459fa718bb Mon Sep 17 00:00:00 2001 From: Ben Drucker Date: Fri, 1 Sep 2023 13:45:58 -0700 Subject: [PATCH] wire resource to provider and implement tests --- observe/provider.go | 1 + observe/resource_dataset_outbound_share.go | 10 ++- .../resource_dataset_outbound_share_test.go | 67 +++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 observe/resource_dataset_outbound_share_test.go diff --git a/observe/provider.go b/observe/provider.go index 7e1c02cc..220b9b7d 100644 --- a/observe/provider.go +++ b/observe/provider.go @@ -163,6 +163,7 @@ func Provider() *schema.Provider { "observe_rbac_statement": resourceRbacStatement(), "observe_filedrop": resourceFiledrop(), "observe_snowflake_share_outbound": resourceSnowflakeShareOutbound(), + "observe_dataset_outbound_share": resourceDatasetOutboundShare(), }, TerraformVersion: version.ProviderVersion, } diff --git a/observe/resource_dataset_outbound_share.go b/observe/resource_dataset_outbound_share.go index 2681aef9..eae02b11 100644 --- a/observe/resource_dataset_outbound_share.go +++ b/observe/resource_dataset_outbound_share.go @@ -2,6 +2,7 @@ package observe import ( "context" + "errors" "fmt" "time" @@ -134,7 +135,7 @@ func resourceDatasetOutboundShareCreate(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - shareId, err := oid.NewOID(d.Get("share").(string)) + shareId, err := oid.NewOID(d.Get("outbound_share").(string)) if err != nil { return diag.FromErr(err) } @@ -277,7 +278,12 @@ func waitDatasetOutboundShareLive(ctx context.Context, ds *gql.DatasetOutboundSh switch resp.Status.State { case gql.DatasetOutboundShareStateError, gql.DatasetOutboundShareStateUnavailable: - return nil, string(resp.Status.State), fmt.Errorf("dataset outbound share is in %q state (%s)", resp.Status.State, resp.Status.Error) + msg := fmt.Sprintf("dataset outbound share is in %q state", resp.Status.State) + if resp.Status.Error != nil { + msg += fmt.Sprintf(": %s", *resp.Status.Error) + } + + return nil, string(resp.Status.State), errors.New(msg) } return resp, string(resp.Status.State), nil diff --git a/observe/resource_dataset_outbound_share_test.go b/observe/resource_dataset_outbound_share_test.go new file mode 100644 index 00000000..e5524e9f --- /dev/null +++ b/observe/resource_dataset_outbound_share_test.go @@ -0,0 +1,67 @@ +package observe + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccObserveDatasetOutboundShare(t *testing.T) { + randomPrefix := acctest.RandomWithPrefix("tf") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: fmt.Sprintf(configPreamble+datastreamConfigPreamble+` + resource "observe_snowflake_share_outbound" "test" { + workspace = data.observe_workspace.default.oid + name = "%[1]s" + description = "test description" + + account { + account = "io79077" + organization = "HC83707" + } + } + + resource "observe_dataset" "test" { + workspace = data.observe_workspace.default.oid + name = "%[1]s-ds" + + inputs = { + "test" = observe_datastream.test.dataset + } + + stage {} + } + + resource "observe_dataset_outbound_share" "test" { + workspace = data.observe_workspace.default.oid + description = "test description" + name = "%[1]s" + dataset = observe_dataset.test.oid + outbound_share = observe_snowflake_share_outbound.test.oid + schema_name = "%[1]s" + view_name = "%[1]s" + freshness_goal = "15m" + } + `, randomPrefix), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("observe_dataset_outbound_share.test", "workspace"), + resource.TestCheckResourceAttrSet("observe_dataset_outbound_share.test", "oid"), + resource.TestCheckResourceAttr("observe_dataset_outbound_share.test", "name", randomPrefix), + resource.TestCheckResourceAttr("observe_dataset_outbound_share.test", "description", "test description"), + resource.TestCheckResourceAttrPair("observe_dataset_outbound_share.test", "dataset", "observe_dataset.test", "oid"), + resource.TestCheckResourceAttrPair("observe_dataset_outbound_share.test", "outbound_share", "observe_snowflake_share_outbound.test", "oid"), + resource.TestCheckResourceAttr("observe_dataset_outbound_share.test", "schema_name", randomPrefix), + resource.TestCheckResourceAttr("observe_dataset_outbound_share.test", "view_name", randomPrefix), + resource.TestCheckResourceAttr("observe_dataset_outbound_share.test", "freshness_goal", "15m"), + ), + }, + }, + }) +}