Fix some style things, handle errors.
Fix a typo, follow our acceptance test naming guidelines, simplify some logic, and handle an unhandled error.
This commit is contained in:
parent
aae44290cd
commit
d59d0a0673
|
@ -20,8 +20,6 @@ import (
|
||||||
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"github.com/hashicorp/errwrap"
|
"github.com/hashicorp/errwrap"
|
||||||
"github.com/hashicorp/terraform/helper/pathorcontents"
|
"github.com/hashicorp/terraform/helper/pathorcontents"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
@ -98,7 +96,7 @@ func validateExtensionHeaders(v interface{}, k string) (ws []string, errors []er
|
||||||
func validateHttpMethod(v interface{}, k string) (ws []string, errs []error) {
|
func validateHttpMethod(v interface{}, k string) (ws []string, errs []error) {
|
||||||
value := v.(string)
|
value := v.(string)
|
||||||
value = strings.ToUpper(value)
|
value = strings.ToUpper(value)
|
||||||
if !regexp.MustCompile(`^(GET|HEAD|PUT|DELETE)$`).MatchString(value) {
|
if value != "GET" && value != "HEAD" && value != "PUT" && value != "DELETE" {
|
||||||
errs = append(errs, errors.New("http_method must be one of [GET|HEAD|PUT|DELETE]"))
|
errs = append(errs, errors.New("http_method must be one of [GET|HEAD|PUT|DELETE]"))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -149,14 +147,7 @@ func dataSourceGoogleSignedUrlRead(d *schema.ResourceData, meta interface{}) err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// object path
|
urlData.Path = fmt.Sprintf("/%s/%s", d.Get("bucket").(string), d.Get("path").(string))
|
||||||
path := []string{
|
|
||||||
"",
|
|
||||||
d.Get("bucket").(string),
|
|
||||||
d.Get("path").(string),
|
|
||||||
}
|
|
||||||
objectPath := strings.Join(path, "/")
|
|
||||||
urlData.Path = objectPath
|
|
||||||
|
|
||||||
// Load JWT Config from Google Credentials
|
// Load JWT Config from Google Credentials
|
||||||
jwtConfig, err := loadJwtConfig(d, config)
|
jwtConfig, err := loadJwtConfig(d, config)
|
||||||
|
|
|
@ -99,7 +99,7 @@ func TestUrlData_SignedUrl(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDatasourceSignedUrl_basic(t *testing.T) {
|
func TestAccStorageSignedUrl_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
|
@ -114,7 +114,7 @@ func TestDatasourceSignedUrl_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDatasourceSignedUrl_accTest(t *testing.T) {
|
func TestAccStorageSignedUrl_accTest(t *testing.T) {
|
||||||
bucketName := fmt.Sprintf("tf-test-bucket-%d", acctest.RandInt())
|
bucketName := fmt.Sprintf("tf-test-bucket-%d", acctest.RandInt())
|
||||||
|
|
||||||
headers := map[string]string{
|
headers := map[string]string{
|
||||||
|
@ -127,7 +127,7 @@ func TestDatasourceSignedUrl_accTest(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccTestGoogleStorageObjectSingedUrl(bucketName),
|
Config: testAccTestGoogleStorageObjectSignedURL(bucketName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccGoogleSignedUrlRetrieval("data.google_storage_object_signed_url.story_url", nil),
|
testAccGoogleSignedUrlRetrieval("data.google_storage_object_signed_url.story_url", nil),
|
||||||
testAccGoogleSignedUrlRetrieval("data.google_storage_object_signed_url.story_url_w_headers", headers),
|
testAccGoogleSignedUrlRetrieval("data.google_storage_object_signed_url.story_url_w_headers", headers),
|
||||||
|
@ -168,7 +168,10 @@ func testAccGoogleSignedUrlRetrieval(n string, headers map[string]string) resour
|
||||||
// create HTTP request
|
// create HTTP request
|
||||||
url := a["signed_url"]
|
url := a["signed_url"]
|
||||||
method := a["http_method"]
|
method := a["http_method"]
|
||||||
req, _ := http.NewRequest(method, url, nil)
|
req, err := http.NewRequest(method, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Add extension headers to request, if provided
|
// Add extension headers to request, if provided
|
||||||
for k, v := range headers {
|
for k, v := range headers {
|
||||||
|
@ -216,7 +219,7 @@ data "google_storage_object_signed_url" "blerg" {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
func testAccTestGoogleStorageObjectSingedUrl(bucketName string) string {
|
func testAccTestGoogleStorageObjectSignedURL(bucketName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_storage_bucket" "bucket" {
|
resource "google_storage_bucket" "bucket" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
|
|
Loading…
Reference in New Issue