Skip to content

Commit 6702bcd

Browse files
Implemented a simple PascalCase function to remove strcase dependency (#4428) (#2899)
* Implemented a simple PascalCase function to remove strcase dependency * Renamed PascalCase -> SnakeToPascalCase Signed-off-by: Modular Magician <[email protected]>
1 parent 338f15f commit 6702bcd

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

.changelog/4428.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/resource_compute_instance_from_machine_image.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"log"
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8-
strcase "github.com/stoewer/go-strcase"
98
computeBeta "google.golang.org/api/compute/v0.beta"
109
compute "google.golang.org/api/compute/v1"
1110
)
@@ -155,7 +154,7 @@ func resourceComputeInstanceFromMachineImageCreate(d *schema.ResourceData, meta
155154
// Assume for now that all fields are exact snake_case versions of the API fields.
156155
// This won't necessarily always be true, but it serves as a good approximation and
157156
// can be adjusted later as we discover issues.
158-
instance.ForceSendFields = append(instance.ForceSendFields, strcase.UpperCamelCase(f))
157+
instance.ForceSendFields = append(instance.ForceSendFields, SnakeToPascalCase(f))
159158
}
160159
}
161160

google-beta/resource_compute_instance_from_template.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"log"
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8-
strcase "github.com/stoewer/go-strcase"
98
computeBeta "google.golang.org/api/compute/v0.beta"
109
compute "google.golang.org/api/compute/v1"
1110
)
@@ -154,7 +153,7 @@ func resourceComputeInstanceFromTemplateCreate(d *schema.ResourceData, meta inte
154153
// Assume for now that all fields are exact snake_case versions of the API fields.
155154
// This won't necessarily always be true, but it serves as a good approximation and
156155
// can be adjusted later as we discover issues.
157-
instance.ForceSendFields = append(instance.ForceSendFields, strcase.UpperCamelCase(f))
156+
instance.ForceSendFields = append(instance.ForceSendFields, SnakeToPascalCase(f))
158157
}
159158
}
160159

google-beta/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,11 @@ func generateUserAgentString(d TerraformResourceData, currentUserAgent string) (
472472

473473
return currentUserAgent, nil
474474
}
475+
476+
func SnakeToPascalCase(s string) string {
477+
split := strings.Split(s, "_")
478+
for i := range split {
479+
split[i] = strings.Title(split[i])
480+
}
481+
return strings.Join(split, "")
482+
}

google-beta/utils_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,13 @@ func TestConflictError(t *testing.T) {
597597
}
598598
// skipping negative tests as other cases may be added later.
599599
}
600+
601+
func TestSnakeToPascalCase(t *testing.T) {
602+
input := "boot_disk"
603+
expected := "BootDisk"
604+
actual := SnakeToPascalCase(input)
605+
606+
if actual != expected {
607+
t.Fatalf("(%s) did not match expected value: %s", actual, expected)
608+
}
609+
}

0 commit comments

Comments
 (0)