Skip to content

Commit

Permalink
wire resource to provider and implement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bendrucker committed Sep 1, 2023
1 parent 4f480ed commit bb27dea
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions observe/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
10 changes: 8 additions & 2 deletions observe/resource_dataset_outbound_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package observe

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
67 changes: 67 additions & 0 deletions observe/resource_dataset_outbound_share_test.go
Original file line number Diff line number Diff line change
@@ -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"),
),
},
},
})
}

0 comments on commit bb27dea

Please sign in to comment.