Skip to content

Commit

Permalink
fix incorrect update reference (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist authored Oct 17, 2022
1 parent 762231b commit a22ea5f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion fastly/block_fastly_service_logging_bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (h *BigQueryLoggingServiceAttributeHandler) Update(_ context.Context, d *sc
if v, ok := modified["template_suffix"]; ok {
opts.Template = gofastly.String(v.(string))
}
if v, ok := modified["user"]; ok {
if v, ok := modified["email"]; ok {
opts.User = gofastly.String(v.(string))
}
if v, ok := modified["secret_key"]; ok {
Expand Down
44 changes: 33 additions & 11 deletions fastly/block_fastly_service_logging_bigquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func TestAccFastlyServiceVCL_bigquerylogging(t *testing.T) {

name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
bqName := fmt.Sprintf("bq %s", acctest.RandString(10))
email := "[email protected]"
emailUpdate := "[email protected]"

secretKey, err := generateKey()
if err != nil {
Expand All @@ -32,10 +34,17 @@ func TestAccFastlyServiceVCL_bigquerylogging(t *testing.T) {
CheckDestroy: testAccCheckServiceVCLDestroy,
Steps: []resource.TestStep{
{
Config: testAccServiceVCLConfigBigQuery(name, bqName, secretKey),
Config: testAccServiceVCLConfigBigQuery(name, bqName, secretKey, email),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceVCLExists("fastly_service_vcl.foo", &service),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName, email),
),
},
{
Config: testAccServiceVCLConfigBigQuery(name, bqName, secretKey, emailUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceVCLExists("fastly_service_vcl.foo", &service),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName, emailUpdate),
),
},
},
Expand All @@ -47,6 +56,8 @@ func TestAccFastlyServiceVCL_bigquerylogging_compute(t *testing.T) {

name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
bqName := fmt.Sprintf("bq %s", acctest.RandString(10))
email := "[email protected]"
emailUpdate := "[email protected]"

secretKey, err := generateKey()
if err != nil {
Expand All @@ -61,10 +72,17 @@ func TestAccFastlyServiceVCL_bigquerylogging_compute(t *testing.T) {
CheckDestroy: testAccCheckServiceVCLDestroy,
Steps: []resource.TestStep{
{
Config: testAccServiceVCLConfigBigQueryCompute(name, bqName, secretKey),
Config: testAccServiceVCLConfigBigQueryCompute(name, bqName, secretKey, email),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceVCLExists("fastly_service_compute.foo", &service),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName, email),
),
},
{
Config: testAccServiceVCLConfigBigQueryCompute(name, bqName, secretKey, emailUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceVCLExists("fastly_service_compute.foo", &service),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName, emailUpdate),
),
},
},
Expand Down Expand Up @@ -116,7 +134,7 @@ func TestBigqueryloggingEnvDefaultFuncAttributes(t *testing.T) {
}
}

func testAccCheckFastlyServiceVCLAttributesBQ(service *gofastly.ServiceDetail, name, bqName string) resource.TestCheckFunc {
func testAccCheckFastlyServiceVCLAttributesBQ(service *gofastly.ServiceDetail, name, bqName, email string) resource.TestCheckFunc {
return func(_ *terraform.State) error {
if service.Name != name {
return fmt.Errorf("bad name, expected (%s), got (%s)", name, service.Name)
Expand All @@ -139,11 +157,15 @@ func testAccCheckFastlyServiceVCLAttributesBQ(service *gofastly.ServiceDetail, n
return fmt.Errorf("bigQuery logging endpoint name mismatch, expected: %s, got: %#v", bqName, bqList[0].Name)
}

if bqList[0].User != email {
return fmt.Errorf("bigQuery logging endpoint user/email mismatch, expected: %s, got: %#v", email, bqList[0].User)
}

return nil
}
}

func testAccServiceVCLConfigBigQuery(name, gcsName, secretKey string) string {
func testAccServiceVCLConfigBigQuery(name, gcsName, secretKey, email string) string {
backendName := fmt.Sprintf("%s.aws.amazon.com", acctest.RandString(3))
domainName := fmt.Sprintf("fastly-test.tf-%s.com", acctest.RandString(10))
return fmt.Sprintf(`
Expand All @@ -162,8 +184,8 @@ resource "fastly_service_vcl" "foo" {
logging_bigquery {
name = "%s"
email = "[email protected]"
secret_key = trimspace(%q)
email = "%s"
project_id = "example-gcp-project"
dataset = "example_bq_dataset"
table = "example_bq_table"
Expand All @@ -172,10 +194,10 @@ resource "fastly_service_vcl" "foo" {
}
force_destroy = true
}`, name, domainName, backendName, gcsName, secretKey)
}`, name, domainName, backendName, gcsName, secretKey, email)
}

func testAccServiceVCLConfigBigQueryCompute(name, gcsName, secretKey string) string {
func testAccServiceVCLConfigBigQueryCompute(name, gcsName, secretKey, email string) string {
backendName := fmt.Sprintf("%s.aws.amazon.com", acctest.RandString(3))
domainName := fmt.Sprintf("fastly-test.tf-%s.com", acctest.RandString(10))
return fmt.Sprintf(`
Expand All @@ -194,8 +216,8 @@ resource "fastly_service_compute" "foo" {
logging_bigquery {
name = "%s"
email = "[email protected]"
secret_key = trimspace(%q)
email = "%s"
project_id = "example-gcp-project"
dataset = "example_bq_dataset"
table = "example_bq_table"
Expand All @@ -207,7 +229,7 @@ resource "fastly_service_compute" "foo" {
}
force_destroy = true
}`, name, domainName, backendName, gcsName, secretKey)
}`, name, domainName, backendName, gcsName, secretKey, email)
}

func setBQEnv(email, secretKey string, t *testing.T) func() {
Expand Down

0 comments on commit a22ea5f

Please sign in to comment.