forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_google_cloudfunctions2_function_test.go
75 lines (65 loc) · 2.13 KB
/
data_source_google_cloudfunctions2_function_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package google
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccDataSourceGoogleCloudFunctions2Function_basic(t *testing.T) {
t.Parallel()
funcDataNameHttp := "data.google_cloudfunctions2_function.function_http_v2"
functionName := fmt.Sprintf("tf-test-%s", randString(t, 10))
bucketName := fmt.Sprintf("tf-test-bucket-%d", randInt(t))
zipFilePath := "./test-fixtures/cloudfunctions2/function-source.zip"
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudfunctions2functionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleCloudFunctions2FunctionConfig(functionName,
bucketName, zipFilePath),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceStateWithIgnores(funcDataNameHttp,
"google_cloudfunctions2_function.function_http_v2", map[string]struct{}{"build_config.0.source.0.storage_source.0.bucket": {}, "build_config.0.source.0.storage_source.0.object": {}}),
),
},
},
})
}
func testAccDataSourceGoogleCloudFunctions2FunctionConfig(functionName, bucketName, zipFilePath string) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "bucket" {
name = "%s"
location = "US"
}
resource "google_storage_bucket_object" "object" {
name = "function-source.zip"
bucket = google_storage_bucket.bucket.name
source = "%s"
}
resource "google_cloudfunctions2_function" "function_http_v2" {
name = "%s"
location = "us-central1"
description = "a new function"
build_config {
runtime = "nodejs12"
entry_point = "helloHttp"
source {
storage_source {
bucket = google_storage_bucket.bucket.name
object = google_storage_bucket_object.object.name
}
}
}
service_config {
max_instance_count = 1
available_memory = "256Mi"
timeout_seconds = 60
}
}
data "google_cloudfunctions2_function" "function_http_v2" {
name = google_cloudfunctions2_function.function_http_v2.name
location = "us-central1"
}
`, bucketName, zipFilePath, functionName)
}