Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devcenter: updating Max to Maximum and updating the website category #3160

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading