-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3160 from hashicorp/f/updating-devcenter
devcenter: updating `Max` to `Maximum` and updating the website category
- Loading branch information
Showing
4 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tools/importer-rest-api-specs/components/schema/processors/field_name_max_to_maximum.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
56 changes: 56 additions & 0 deletions
56
tools/importer-rest-api-specs/components/schema/processors/field_name_max_to_maximum_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters