Skip to content

Commit

Permalink
Merge pull request #261 from dbt-labs/update-testing-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
b-per authored May 28, 2024
2 parents e7aef32 + 29ca0e9 commit 1a471c9
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 113 deletions.
4 changes: 4 additions & 0 deletions pkg/framework/acctest_helper/acctest_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ func TestAccPreCheck(t *testing.T) {
t.Fatal("DBT_CLOUD_TOKEN must be set for acceptance tests")
}
}

func IsDbtCloudPR() bool {
return os.Getenv("DBT_CLOUD_ACCOUNT_ID") == "1"
}
15 changes: 11 additions & 4 deletions pkg/framework/objects/notification/data_source_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ import (

func TestAccDbtCloudNotificationDataSource(t *testing.T) {

var userID string
if acctest_helper.IsDbtCloudPR() {
userID = "1"
} else {
userID = "100"
}

randomProjectName := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

config := notification(randomProjectName)
config := notification(randomProjectName, userID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -43,7 +50,7 @@ func TestAccDbtCloudNotificationDataSource(t *testing.T) {
})
}

func notification(projectName string) string {
func notification(projectName, userID string) string {
return fmt.Sprintf(`
resource "dbtcloud_project" "test_notification_project" {
name = "%s"
Expand Down Expand Up @@ -71,7 +78,7 @@ func notification(projectName string) string {
}
resource "dbtcloud_notification" "test_notification_external" {
user_id = 100
user_id = %s
on_failure = [dbtcloud_job.test_notification_job_1.id]
notification_type = 4
external_email = "[email protected]"
Expand All @@ -80,5 +87,5 @@ func notification(projectName string) string {
data "dbtcloud_notification" "test_notification_external" {
notification_id = dbtcloud_notification.test_notification_external.id
}
`, projectName, acctest_helper.DBT_CLOUD_VERSION)
`, projectName, acctest_helper.DBT_CLOUD_VERSION, userID)
}
31 changes: 19 additions & 12 deletions pkg/framework/objects/notification/resource_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import (

func TestAccDbtCloudNotificationResource(t *testing.T) {

var userID string
if acctest_helper.IsDbtCloudPR() {
userID = "1"
} else {
userID = "100"
}

projectName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

resource.Test(t, resource.TestCase{
Expand All @@ -23,7 +30,7 @@ func TestAccDbtCloudNotificationResource(t *testing.T) {
CheckDestroy: testAccCheckDbtCloudNotificationDestroy,
Steps: []resource.TestStep{
{
Config: testAccDbtCloudNotificationResourceCreateNotifications(projectName),
Config: testAccDbtCloudNotificationResourceCreateNotifications(projectName, userID),
Check: resource.ComposeTestCheckFunc(
testAccCheckDbtCloudNotificationExists(
"dbtcloud_notification.test_notification_internal",
Expand Down Expand Up @@ -71,7 +78,7 @@ func TestAccDbtCloudNotificationResource(t *testing.T) {
},
// MODIFY
{
Config: testAccDbtCloudNotificationResourceModifyNotifications(projectName),
Config: testAccDbtCloudNotificationResourceModifyNotifications(projectName, userID),
Check: resource.ComposeTestCheckFunc(
testAccCheckDbtCloudNotificationExists(
"dbtcloud_notification.test_notification_internal",
Expand Down Expand Up @@ -150,46 +157,46 @@ resource "dbtcloud_job" "test_notification_job_2" {
`, projectName, acctest_helper.DBT_CLOUD_VERSION)
}

func testAccDbtCloudNotificationResourceCreateNotifications(projectName string) string {
func testAccDbtCloudNotificationResourceCreateNotifications(projectName, userID string) string {

notificationsConfig := `
notificationsConfig := fmt.Sprintf(`
resource "dbtcloud_notification" "test_notification_internal" {
user_id = 100
user_id = %s
on_success = [dbtcloud_job.test_notification_job_1.id]
on_failure = [dbtcloud_job.test_notification_job_2.id]
on_cancel = [dbtcloud_job.test_notification_job_1.id, dbtcloud_job.test_notification_job_2.id]
notification_type = 1
}
resource "dbtcloud_notification" "test_notification_external" {
user_id = 100
user_id = %s
on_failure = [dbtcloud_job.test_notification_job_2.id]
notification_type = 4
external_email = "[email protected]"
}
`
`, userID, userID)
return testAccDbtCloudNotificationResourceBasicConfig(projectName) + "\n" + notificationsConfig
}

func testAccDbtCloudNotificationResourceModifyNotifications(projectName string) string {
func testAccDbtCloudNotificationResourceModifyNotifications(projectName, userID string) string {

notificationsConfig := `
notificationsConfig := fmt.Sprintf(`
resource "dbtcloud_notification" "test_notification_internal" {
user_id = 100
user_id = %s
on_success = [dbtcloud_job.test_notification_job_1.id]
on_failure = [dbtcloud_job.test_notification_job_2.id]
on_cancel = []
notification_type = 1
}
resource "dbtcloud_notification" "test_notification_external" {
user_id = 100
user_id = %s
on_failure = [dbtcloud_job.test_notification_job_2.id]
on_cancel = [dbtcloud_job.test_notification_job_1.id]
notification_type = 4
external_email = "[email protected]"
}
`
`, userID, userID)
return testAccDbtCloudNotificationResourceBasicConfig(projectName) + "\n" + notificationsConfig
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import (

func TestAccDbtCloudPartialNotificationResource(t *testing.T) {

var userID string
if acctest_helper.IsDbtCloudPR() {
userID = "1"
} else {
userID = "100"
}

projectName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

resource.Test(t, resource.TestCase{
Expand All @@ -24,6 +31,7 @@ func TestAccDbtCloudPartialNotificationResource(t *testing.T) {
{
Config: testAccDbtCloudPartialNotificationResourceCreatePartialNotifications(
projectName,
userID,
),
Check: resource.ComposeTestCheckFunc(
testAccCheckDbtCloudPartialNotificationExists(
Expand Down Expand Up @@ -74,6 +82,7 @@ func TestAccDbtCloudPartialNotificationResource(t *testing.T) {
{
Config: testAccDbtCloudPartialNotificationResourceModifyPartialNotifications(
projectName,
userID,
),
Check: resource.ComposeTestCheckFunc(
testAccCheckDbtCloudPartialNotificationExists(
Expand Down Expand Up @@ -150,59 +159,59 @@ resource "dbtcloud_job" "test_notification_job_2" {
}

func testAccDbtCloudPartialNotificationResourceCreatePartialNotifications(
projectName string,
projectName, userID string,
) string {

notificationsConfig := `
notificationsConfig := fmt.Sprintf(`
resource "dbtcloud_partial_notification" "test_notification_internal" {
user_id = 100
user_id = %s
on_success = [dbtcloud_job.test_notification_job_1.id]
on_failure = [dbtcloud_job.test_notification_job_2.id]
on_cancel = [dbtcloud_job.test_notification_job_1.id, dbtcloud_job.test_notification_job_2.id]
notification_type = 1
}
resource "dbtcloud_partial_notification" "test_notification_external" {
user_id = 100
user_id = %s
on_failure = [dbtcloud_job.test_notification_job_2.id]
notification_type = 4
external_email = "[email protected]"
}
`
`, userID, userID)
return testAccDbtCloudPartialNotificationResourceBasicConfig(
projectName,
) + "\n" + notificationsConfig
}

func testAccDbtCloudPartialNotificationResourceModifyPartialNotifications(
projectName string,
projectName, userID string,
) string {

notificationsConfig := `
notificationsConfig := fmt.Sprintf(`
resource "dbtcloud_partial_notification" "test_notification_internal" {
user_id = 100
user_id = %s
on_success = [dbtcloud_job.test_notification_job_1.id]
on_failure = [dbtcloud_job.test_notification_job_2.id]
on_cancel = []
notification_type = 1
}
resource "dbtcloud_partial_notification" "test_notification_external" {
user_id = 100
user_id = %s
on_failure = [dbtcloud_job.test_notification_job_2.id]
on_cancel = [dbtcloud_job.test_notification_job_1.id]
notification_type = 4
external_email = "[email protected]"
}
resource "dbtcloud_partial_notification" "test_notification_external2" {
user_id = 100
user_id = %s
on_success = [dbtcloud_job.test_notification_job_1.id, dbtcloud_job.test_notification_job_2.id]
notification_type = 4
external_email = "[email protected]"
depends_on = [dbtcloud_partial_notification.test_notification_external]
}
`
`, userID, userID, userID)
return testAccDbtCloudPartialNotificationResourceBasicConfig(
projectName,
) + "\n" + notificationsConfig
Expand Down
7 changes: 6 additions & 1 deletion pkg/framework/objects/user/data_source_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import (

func TestAccDbtCloudUserDataSource(t *testing.T) {

userEmail := "beno" + "it" + ".per" + "igaud" + "@" + "fisht" + "ownanalytics" + "." + "com"
var userEmail string
if acctest_helper.IsDbtCloudPR() {
userEmail = "d" + "ev@" + "db" + "tla" + "bs.c" + "om"
} else {
userEmail = "beno" + "it" + ".per" + "igaud" + "@" + "fisht" + "ownanalytics" + "." + "com"
}

config := user(userEmail)

Expand Down
6 changes: 6 additions & 0 deletions pkg/sdkv2/data_sources/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package data_sources_test

import (
"os"

"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/provider"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand All @@ -15,3 +17,7 @@ func providers() map[string]*schema.Provider {
"dbtcloud": p,
}
}

func isDbtCloudPR() bool {
return os.Getenv("DBT_CLOUD_ACCOUNT_ID") == "1"
}
90 changes: 44 additions & 46 deletions pkg/sdkv2/data_sources/privatelink_endpoint_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package data_sources_test

import (
"fmt"
"log"
"os"
"testing"

Expand All @@ -12,57 +11,56 @@ import (
func TestAccDbtCloudPrivatelinkEndpointDataSource(t *testing.T) {

// we only test this explicitly as we can't create resources and need to read from existing ones
if os.Getenv("DBT_ACCEPTANCE_TEST_PRIVATE_LINK") != "" {
if os.Getenv("DBT_ACCEPTANCE_TEST_PRIVATE_LINK") == "" {
t.Skip("Skipping acceptance tests as DBT_ACCEPTANCE_TEST_PRIVATE_LINK is not set")
}

endpointName := os.Getenv("DBT_ACCEPTANCE_TEST_PRIVATE_LINK_NAME")
endpointURL := os.Getenv("DBT_ACCEPTANCE_TEST_PRIVATE_LINK_URL")
endpointName := os.Getenv("DBT_ACCEPTANCE_TEST_PRIVATE_LINK_NAME")
endpointURL := os.Getenv("DBT_ACCEPTANCE_TEST_PRIVATE_LINK_URL")

// different configurations whether we provide the endpoint name and/or url
config := privatelinkEndpoint(endpointName, endpointURL)
configNoURL := privatelinkEndpoint(endpointName, "")
// different configurations whether we provide the endpoint name and/or url
config := privatelinkEndpoint(endpointName, endpointURL)
configNoURL := privatelinkEndpoint(endpointName, "")

configNoName := privatelinkEndpoint("", endpointURL)
configNoName := privatelinkEndpoint("", endpointURL)

check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"data.dbtcloud_privatelink_endpoint.test",
"name",
endpointName,
),
resource.TestCheckResourceAttr(
"data.dbtcloud_privatelink_endpoint.test",
"private_link_endpoint_url",
endpointURL,
),
resource.TestCheckResourceAttrSet("data.dbtcloud_privatelink_endpoint.test", "id"),
resource.TestCheckResourceAttrSet(
"data.dbtcloud_privatelink_endpoint.test",
"cidr_range",
),
resource.TestCheckResourceAttrSet("data.dbtcloud_privatelink_endpoint.test", "type"),
resource.TestCheckResourceAttrSet("data.dbtcloud_privatelink_endpoint.test", "state"),
)
check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"data.dbtcloud_privatelink_endpoint.test",
"name",
endpointName,
),
resource.TestCheckResourceAttr(
"data.dbtcloud_privatelink_endpoint.test",
"private_link_endpoint_url",
endpointURL,
),
resource.TestCheckResourceAttrSet("data.dbtcloud_privatelink_endpoint.test", "id"),
resource.TestCheckResourceAttrSet(
"data.dbtcloud_privatelink_endpoint.test",
"cidr_range",
),
resource.TestCheckResourceAttrSet("data.dbtcloud_privatelink_endpoint.test", "type"),
resource.TestCheckResourceAttrSet("data.dbtcloud_privatelink_endpoint.test", "state"),
)

resource.ParallelTest(t, resource.TestCase{
Providers: providers(),
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
{
Config: configNoURL,
Check: check,
},
{
Config: configNoName,
Check: check,
},
resource.ParallelTest(t, resource.TestCase{
Providers: providers(),
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
})
} else {
log.Println("WARNING: The test is skipped as DBT_TEST_PRIVATE_LINK is not set")
}
{
Config: configNoURL,
Check: check,
},
{
Config: configNoName,
Check: check,
},
},
})
}

func privatelinkEndpoint(endpointName, endpointURL string) string {
Expand Down
4 changes: 3 additions & 1 deletion pkg/sdkv2/data_sources/user_groups_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
func TestDbtCloudUserGroupsDataSource(t *testing.T) {

var userID int
if value := os.Getenv("CI"); value != "" {
if isDbtCloudPR() {
userID = 1
} else if os.Getenv("CI") != "" {
userID = 54461
} else {
userID = 32
Expand Down
Loading

0 comments on commit 1a471c9

Please sign in to comment.