-
Notifications
You must be signed in to change notification settings - Fork 104
Generator redesign read meta for resource name to class struct (DCNE-345) #1350
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
base: generator_redesign
Are you sure you want to change the base?
Changes from all commits
46f5495
9031963
a31cba7
9012df2
9b7d3ab
ba20e14
5d99200
f7a64e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,10 @@ | ||
package test | ||
|
||
import ( | ||
"runtime" | ||
"strings" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func InitializeTest(t *testing.T, functionCounter int) { | ||
println("Executing:", GetTestName(t, functionCounter+1)) | ||
} | ||
|
||
func GetTestName(t *testing.T, functionCounter int) string { | ||
counter, _, _, success := runtime.Caller(functionCounter + 1) | ||
if !success { | ||
t.Fatalf("Failed to get caller information: %v", success) | ||
} | ||
splittedName := strings.Split(runtime.FuncForPC(counter).Name(), ".") | ||
return splittedName[len(splittedName)-1] | ||
func InitializeTest(t *testing.T) { | ||
println(fmt.Sprintf("Executing: %s", t.Name())) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ const ( | |
) | ||
|
||
func TestGetFileNamesFromDirectoryWithExtension(t *testing.T) { | ||
test.InitializeTest(t, 0) | ||
test.InitializeTest(t) | ||
filenames := GetFileNamesFromDirectory(constTestDirectoryForGetFileNamesFromDirectory, false) | ||
assert.NotEmpty(t, filenames, "Expected to get file names from directory, but got empty list") | ||
assert.Equal(t, len(filenames), 3, fmt.Sprintf("Expected to get 2 file names from directory, but got %d", len(filenames))) | ||
|
@@ -30,7 +30,7 @@ func TestGetFileNamesFromDirectoryWithExtension(t *testing.T) { | |
} | ||
|
||
func TestGetFileNamesFromDirectoryWithoutExtension(t *testing.T) { | ||
test.InitializeTest(t, 0) | ||
test.InitializeTest(t) | ||
filenames := GetFileNamesFromDirectory(constTestDirectoryForGetFileNamesFromDirectory, true) | ||
assert.NotEmpty(t, filenames, "Expected to get file names from directory, but got empty list") | ||
assert.Equal(t, len(filenames), 3, fmt.Sprintf("Expected to get 2 file names from directory, but got %d", len(filenames))) | ||
|
@@ -39,3 +39,44 @@ func TestGetFileNamesFromDirectoryWithoutExtension(t *testing.T) { | |
assert.Contains(t, filenames, constTestFile3, fmt.Sprintf("Expected to find file name '%s' in the list, but it was not found", constTestFile3)) | ||
assert.NotContains(t, filenames, constTestDir1, fmt.Sprintf("Expected to not find directory name '%s' in the list, but it was found", constTestDir1)) | ||
} | ||
|
||
func TestUnderscore(t *testing.T) { | ||
test.InitializeTest(t) | ||
|
||
tests := []map[string]string{ | ||
{"input": "tenant", "expected": "tenant"}, | ||
{"input": "Tenant", "expected": "tenant"}, | ||
{"input": "Tenant1", "expected": "tenant1"}, | ||
{"input": "ApplicationEndpointGroup", "expected": "application_endpoint_group"}, | ||
{"input": "Application Endpoint Group", "expected": "application_endpoint_group"}, | ||
} | ||
|
||
for _, test := range tests { | ||
genLogger.Info(fmt.Sprintf("Executing: %s' with input '%s' and expected output '%s'", t.Name(), test["input"], test["expected"])) | ||
result := Underscore(test["input"]) | ||
assert.Equal(t, test["expected"], result, fmt.Sprintf("Expected '%s', but got '%s'", test["expected"], result)) | ||
} | ||
|
||
} | ||
|
||
func TestPlural(t *testing.T) { | ||
test.InitializeTest(t) | ||
|
||
tests := []map[string]string{ | ||
{"input": "monitor_policy", "expected": "monitor_policies"}, | ||
{"input": "annotation", "expected": "annotations"}, | ||
} | ||
|
||
for _, test := range tests { | ||
genLogger.Info(fmt.Sprintf("Executing: %s' with input '%s' and expected output '%s'", t.Name(), test["input"], test["expected"])) | ||
result, err := Plural(test["input"]) | ||
assert.NoError(t, err, fmt.Sprintf("Expected no error, but got '%s'", err)) | ||
assert.Equal(t, test["expected"], result, fmt.Sprintf("Expected '%s', but got '%s'", test["expected"], result)) | ||
} | ||
Comment on lines
+70
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be repeated in some fashion quite a bit. Should this be a function that accept a series of attribute including the tested function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will have a look at creating functions for all the repeating tests |
||
} | ||
|
||
func TestPluralError(t *testing.T) { | ||
test.InitializeTest(t) | ||
_, err := Plural("contracts") | ||
assert.Error(t, err, fmt.Sprintf("Expected error, but got '%s'", err)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also does not account for relational classes right where we need to add relation_ right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will include logic for this