Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
611b33b
chore: remove useless code
alexgarzao Oct 26, 2025
e324603
feat: testgen building end-to-end tests
alexgarzao Oct 26, 2025
2cdca99
chore: turn public GenValidations api
alexgarzao Oct 26, 2025
c2142d2
feat: testgen bulding validation code tests
alexgarzao Oct 26, 2025
f6bdb38
test: add generated validation code test files
alexgarzao Oct 26, 2025
581fa9a
chore: makefile rule to build generated tests and move to the correct
alexgarzao Oct 26, 2025
98b323a
chore: add DO NOT EDIT to all templates
alexgarzao Oct 26, 2025
5591942
chore: fix DO NOT EDIT header
alexgarzao Oct 26, 2025
47d14f6
chore: better func name
alexgarzao Oct 26, 2025
64050fa
doc: initial testgen readme
alexgarzao Oct 27, 2025
2ee054c
chore: remove useless code
alexgarzao Oct 27, 2025
abc9fe5
feat: testgen generating tests to check function validate output
alexgarzao Oct 27, 2025
f06c1cb
test: commit tests generated by testgen
alexgarzao Oct 27, 2025
7bb3ad6
Merge branch 'main' into 93-testgen-function-code-tests
alexgarzao Oct 28, 2025
e0325e6
chore: remove use slice[n] to avoid panic
alexgarzao Oct 28, 2025
4f9fa12
chore: better way to chain calls in the makefile
alexgarzao Oct 28, 2025
427754d
chore: use bitfield to exclude tests to be generated
alexgarzao Oct 29, 2025
b205a3a
chore: add govalidator tag to generated cmp perf tests
alexgarzao Oct 29, 2025
8a8c8f8
feat: generate perf cmp tests in testgen
alexgarzao Oct 29, 2025
c09649e
chore: add generated perf tests
alexgarzao Oct 29, 2025
2f9c8ed
chore: use fmt instead of log
alexgarzao Oct 29, 2025
fd656b3
refact: one func to exec template and format code
alexgarzao Oct 29, 2025
dc1fdf3
Merge branch 'main' into 93-refactor-testgen
alexgarzao Oct 29, 2025
8b5e2b3
Merge branch 'main' into 93-testgen-generating-cmp-perf-tests
alexgarzao Oct 29, 2025
4638353
Merge branch '93-testgen-generating-cmp-perf-tests' into 93-refactor-…
alexgarzao Oct 29, 2025
8d09241
Merge branch 'main' into 93-refactor-testgen
alexgarzao Nov 1, 2025
72a90ec
chore: remove old way to generate cmp benchtests
alexgarzao Nov 2, 2025
f652752
chore: add missed \n in error messages
alexgarzao Nov 4, 2025
10fbd60
chore: remove tests generated by testgen
alexgarzao Nov 7, 2025
b9f15a3
Merge branch 'main' into 93-cleanup-old-tests
alexgarzao Nov 7, 2025
cb5a2bc
chore: remove duplicated slice test
alexgarzao Nov 7, 2025
5ab302c
chore: remove duplicated tests
alexgarzao Nov 7, 2025
9f4d828
chore: remove old end-to-end test generator
alexgarzao Nov 7, 2025
78ed57a
chore: remove old end-to-end tests generated by hand
alexgarzao Nov 7, 2025
8b6f923
chore: remove duplicated tests
alexgarzao Nov 8, 2025
4b13775
chore: update testgen readme
alexgarzao Nov 11, 2025
d7c4ae7
doc: update testgen readme
alexgarzao Nov 11, 2025
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
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ build: clean

testgen:
@echo "Generating tests"
cd testgen/ && rm -f generated_*.go && go run *.go && mv generated_endtoend_*tests.go ../tests/endtoend/ && mv generated_validation_*_test.go ../internal/codegenerator/ && mv generated_function_code_*_test.go ../internal/codegenerator/ && mv generated_cmp_perf_*.go ../tests/cmpbenchtests/generated_tests/
cd testgen/ && rm -f generated_*.go && go run *.go && mv generated_endtoend_*tests.go ../tests/endtoend/ && mv generated_validation_*_test.go ../internal/codegenerator/ && mv generated_function_code_*_test.go ../internal/codegenerator/ && mv generated_cmp_perf_*.go ../tests/cmpbenchtests/

endtoendtests: build
@echo "Running endtoend tests"
Expand All @@ -41,11 +41,9 @@ endtoendtests: build

cmpbenchtests: build
@echo "Running cmp bench tests"
rm -f tests/cmpbenchtests/generated_tests/valid*.go && rm -f tests/cmpbenchtests/generated_tests/types.go
cd tests/cmpbenchtests; go run .
$(VALIDGEN_BIN) tests/cmpbenchtests/generated_tests
$(VALIDGEN_BIN) tests/cmpbenchtests/
go clean -testcache
go test -bench=. -v -benchmem -benchtime=$(BENCH_TIME) ./tests/cmpbenchtests/generated_tests
go test -bench=. -v -benchmem -benchtime=$(BENCH_TIME) ./tests/cmpbenchtests/

setup:
@echo "Setting up"
Expand Down
75 changes: 1 addition & 74 deletions internal/codegenerator/build_func_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/sergi/go-diff/diffmatchpatch"
)

func TestBuildFuncValidatorCode(t *testing.T) {
func TestBuildFuncValidatorCodeFieldOperations(t *testing.T) {
type fields struct {
Struct *analyzer.Struct
}
Expand All @@ -18,79 +18,6 @@ func TestBuildFuncValidatorCode(t *testing.T) {
fields fields
want string
}{
{
name: "Valid struct",
fields: fields{
Struct: &analyzer.Struct{
Struct: parser.Struct{
PackageName: "main",
StructName: "User",
Fields: []parser.Field{
{
FieldName: "FirstName",
Type: common.FieldType{BaseType: "string"},
Tag: `validate:"required"`,
},
{
FieldName: "MyAge",
Type: common.FieldType{BaseType: "uint8"},
Tag: `validate:"required"`,
},
},
},
FieldsValidations: []analyzer.FieldValidations{
{
Validations: []*analyzer.Validation{AssertParserValidation(t, "required")},
},
{
Validations: []*analyzer.Validation{AssertParserValidation(t, "required")},
},
},
},
},
want: `func UserValidate(obj *User) []error {
var errs []error
if !(obj.FirstName != "") {
errs = append(errs, types.NewValidationError("FirstName is required"))
}
if !(obj.MyAge != 0) {
errs = append(errs, types.NewValidationError("MyAge is required"))
}
return errs
}
`,
},
{
name: "FirstName must have 5 characters or more",
fields: fields{
Struct: &analyzer.Struct{
Struct: parser.Struct{
PackageName: "main",
StructName: "User",
Fields: []parser.Field{
{
FieldName: "FirstName",
Type: common.FieldType{BaseType: "string"},
Tag: `validate:"min=5"`,
},
},
},
FieldsValidations: []analyzer.FieldValidations{
{
Validations: []*analyzer.Validation{AssertParserValidation(t, "min=5")},
},
},
},
},
want: `func UserValidate(obj *User) []error {
var errs []error
if !(len(obj.FirstName) >= 5) {
errs = append(errs, types.NewValidationError("FirstName length must be >= 5"))
}
return errs
}
`,
},
{
name: "Field inner op",
fields: fields{
Expand Down
Loading
Loading