Skip to content

Commit

Permalink
Merge pull request #3160 from hashicorp/f/updating-devcenter
Browse files Browse the repository at this point in the history
devcenter: updating `Max` to `Maximum` and updating the website category
  • Loading branch information
tombuildsstuff authored Oct 16, 2023
2 parents 6602e35 + 154ff7a commit 59d6a0e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/resources/devcenter.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ service "DevCenter" {
definition "dev_center_project" {
id = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}"
display_name = "Dev Center Project"
website_subcategory = "Dev Center Project"
website_subcategory = "Dev Center"
description = "Manages a Dev Center Project"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package processors

import (
"fmt"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"strings"
"unicode"
)

var _ FieldNameProcessor = fieldNameMaxToMaximum{}

type fieldNameMaxToMaximum struct{}

func (fieldNameMaxToMaximum) ProcessField(fieldName string, metadata FieldMetadata) (*string, error) {
if strings.HasPrefix(strings.ToLower(fieldName), "max") {
// if this is the literal value `Max`
if strings.EqualFold(fieldName, "max") {
return pointer.To("Maximum"), nil
}

// at this point the word must be longer than 3 words, so we can safely trim it
trimmedValue := fieldName[3:]
firstChar := trimmedValue[0]
if !unicode.IsUpper(rune(firstChar)) {
return nil, nil
}

// If this was `Max{Something}` (being another word) then we should swap this out:
trimmedValue = fmt.Sprintf("Maximum%s", trimmedValue)
return pointer.To(trimmedValue), nil
}

return nil, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package processors

import (
"testing"
)

func TestFieldNameMaxToMaximum_Valid(t *testing.T) {
result, err := fieldNameMaxToMaximum{}.ProcessField("MaxValue", FieldMetadata{})
if err != nil {
t.Fatalf(err.Error())
}

if result == nil {
t.Fatalf("expected result to be non-nil but it was")
}
if *result != "MaximumValue" {
t.Fatalf("expected result to be `MaximumValue` but got %q", *result)
}
}

func TestFieldNameMaxToMaximum_Invalid(t *testing.T) {
result, err := fieldNameMaxToMaximum{}.ProcessField("Maximillian", FieldMetadata{})
if err != nil {
t.Fatalf(err.Error())
}

if result != nil {
t.Fatalf("expected result to be nil but got %q", *result)
}
}

func TestFieldNameMaxToMaximum_LiteralValueOfMax(t *testing.T) {
result, err := fieldNameMaxToMaximum{}.ProcessField("Max", FieldMetadata{})
if err != nil {
t.Fatalf(err.Error())
}
if result == nil {
t.Fatalf("expected result to be non-nil but it was")
}
if *result != "Maximum" {
t.Fatalf("expected result to be `Maximum` but got %q", *result)
}
}

func TestFieldNameMaxToMaximum_LiteralValueOfMaxLowerCase(t *testing.T) {
result, err := fieldNameMaxToMaximum{}.ProcessField("max", FieldMetadata{})
if err != nil {
t.Fatalf(err.Error())
}
if result == nil {
t.Fatalf("expected result to be non-nil but it was")
}
if *result != "Maximum" {
t.Fatalf("expected result to be `Maximum` but got %q", *result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var NamingRules = []FieldNameProcessor{
fieldNameRemoveResourcePrefix{},
fieldNameRenameBoolean{},
fieldNameRenameMislabelledResourceID{},
fieldNameMaxToMaximum{},
}

//TODO: if it's a List[Reference] and the model contains a single field `Id` then flatten this into `_ids`.
Expand Down

0 comments on commit 59d6a0e

Please sign in to comment.