-
Notifications
You must be signed in to change notification settings - Fork 9
chore: add tests for repo #21
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
Open
shivamsouravjha
wants to merge
1
commit into
guiferpa:main
Choose a base branch
from
shivamsouravjha:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,51 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
"log" | ||
) | ||
|
||
|
||
// Test generated using Keploy | ||
func TestErrInvalidPalindromeError(t *testing.T) { | ||
err := &ErrInvalidPalindrome{Value: "not-a-palindrome"} | ||
expected := "invalid palindrome: not-a-palindrome" | ||
if err.Error() != expected { | ||
t.Errorf("Expected %v, got %v", expected, err.Error()) | ||
} | ||
} | ||
|
||
// Test generated using Keploy | ||
func TestPalindromeRuleName(t *testing.T) { | ||
rule := &PalindromeRule{} | ||
expected := "palindrome" | ||
if rule.Name() != expected { | ||
t.Errorf("Expected %v, got %v", expected, rule.Name()) | ||
} | ||
} | ||
|
||
|
||
// Test generated using Keploy | ||
func TestCustomRuleValidation(t *testing.T) { | ||
// Mocking log output | ||
var logOutput string | ||
log.SetOutput(&mockWriter{func(p []byte) (n int, err error) { | ||
logOutput += string(p) | ||
return len(p), nil | ||
}}) | ||
|
||
CustomRuleValidation() | ||
|
||
if logOutput == "" { | ||
t.Error("Expected log output, got none") | ||
} | ||
} | ||
|
||
type mockWriter struct { | ||
writeFunc func(p []byte) (n int, err error) | ||
} | ||
|
||
func (m *mockWriter) Write(p []byte) (n int, err error) { | ||
return m.writeFunc(p) | ||
} | ||
|
This file contains hidden or 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,65 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
|
||
// Test generated using Keploy | ||
func TestErrIsAdultErrorMessage(t *testing.T) { | ||
err := &ErrIsAdult{} | ||
expected := "The client isn't a adult then it isn't allowed buy" | ||
if err.Error() != expected { | ||
t.Errorf("Expected error message '%s', got '%s'", expected, err.Error()) | ||
} | ||
} | ||
|
||
// Test generated using Keploy | ||
func TestIsAdultRuleName(t *testing.T) { | ||
rule := &IsAdultRule{} | ||
expected := "is_adult" | ||
if rule.Name() != expected { | ||
t.Errorf("Expected rule name '%s', got '%s'", expected, rule.Name()) | ||
} | ||
} | ||
|
||
|
||
// Test generated using Keploy | ||
func TestIsAdultRuleValidateEmptyValue(t *testing.T) { | ||
rule := &IsAdultRule{adultAge: 21} | ||
valid, err := rule.Validate("", "", "") | ||
if !valid || err == nil { | ||
t.Errorf("Expected validation to fail with ErrIsAdult, got valid=%v, err=%v", valid, err) | ||
} | ||
} | ||
|
||
|
||
// Test generated using Keploy | ||
func TestIsAdultRuleValidateNonIntegerValue(t *testing.T) { | ||
rule := &IsAdultRule{adultAge: 21} | ||
valid, err := rule.Validate("", "notanumber", "") | ||
if valid || err == nil { | ||
t.Errorf("Expected validation to fail with an error, got valid=%v, err=%v", valid, err) | ||
} | ||
} | ||
|
||
|
||
// Test generated using Keploy | ||
func TestIsAdultRuleValidateUnderage(t *testing.T) { | ||
rule := &IsAdultRule{adultAge: 21} | ||
valid, err := rule.Validate("", "18", "") | ||
if !valid || err == nil { | ||
t.Errorf("Expected validation to fail with ErrIsAdult, got valid=%v, err=%v", valid, err) | ||
} | ||
} | ||
|
||
|
||
// Test generated using Keploy | ||
func TestIsAdultRuleValidateAdult(t *testing.T) { | ||
rule := &IsAdultRule{adultAge: 21} | ||
valid, err := rule.Validate("", "21", "") | ||
if !valid || err != nil { | ||
t.Errorf("Expected validation to pass, got valid=%v, err=%v", valid, err) | ||
} | ||
} | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,75 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"log" | ||
|
||
gody "github.com/guiferpa/gody/v2" | ||
"github.com/guiferpa/gody/v2/rule" | ||
gody "github.com/guiferpa/gody/v2" | ||
"github.com/guiferpa/gody/v2/rule" | ||
) | ||
|
||
func SimpleDefaultValidation() { | ||
b := struct { | ||
Text string `json:"text" validate:"not_empty"` | ||
}{} | ||
|
||
valid, err := gody.DefaultValidate(b, nil) | ||
if err != nil { | ||
if !valid { | ||
log.Println("body do not validated:", err) | ||
} | ||
|
||
switch err.(type) { | ||
case *rule.ErrNotEmpty: | ||
log.Println("not empty error:", err) | ||
|
||
} | ||
} | ||
func SimpleDefaultValidation(text string) error { | ||
b := struct { | ||
Text string `json:"text" validate:"not_empty"` | ||
}{ | ||
Text: text, | ||
} | ||
|
||
valid, err := gody.DefaultValidate(b, nil) | ||
if err != nil { | ||
if !valid { | ||
log.Println("body do not validated:", err) | ||
} | ||
|
||
switch err.(type) { | ||
8000 case *rule.ErrNotEmpty: | ||
log.Println("not empty error:", err) | ||
} | ||
} | ||
return err | ||
} | ||
|
||
func SimplePureValidation() { | ||
b := struct { | ||
Text string `json:"text" validate:"not_empty"` | ||
}{} | ||
|
||
rules := []gody.Rule{ | ||
rule.NotEmpty, | ||
} | ||
valid, err := gody.Validate(b, rules) | ||
if err != nil { | ||
if !valid { | ||
log.Println("body do not validated:", err) | ||
} | ||
|
||
switch err.(type) { | ||
case *rule.ErrNotEmpty: | ||
log.Println("not empty error:", err) | ||
|
||
} | ||
} | ||
func SimplePureValidation(text string) error { | ||
b := struct { | ||
Text string `json:"text" validate:"not_empty"` | ||
}{ | ||
Text: text, | ||
} | ||
|
||
rules := []gody.Rule{ | ||
rule.NotEmpty, | ||
} | ||
valid, err := gody.Validate(b, rules) | ||
if err != nil { | ||
if !valid { | ||
log.Println("body do not validated:", err) | ||
} | ||
|
||
switch err.(type) { | ||
case *rule.ErrNotEmpty: | ||
log.Println("not empty error:", err) | ||
} | ||
} | ||
return err | ||
} | ||
|
||
func SimpleValidationFromValidator() { | ||
b := struct { | ||
Text string `json:"text" validate:"not_empty"` | ||
}{} | ||
|
||
validator := gody.NewValidator() | ||
|
||
if err := validator.AddRules(rule.NotEmpty); err != nil { | ||
log.Println(err) | ||
return | ||
} | ||
|
||
valid, err := validator.Validate(b) | ||
if err != nil { | ||
if !valid { | ||
log.Println("body do not validated:", err) | ||
} | ||
|
||
switch err.(type) { | ||
case *rule.ErrNotEmpty: | ||
log.Println("not empty error:", err) | ||
|
||
} | ||
} | ||
func SimpleValidationFromValidator(text string) error { | ||
b := struct { | ||
Text string `json:"text" validate:"not_empty"` | ||
}{ | ||
Text: text, | ||
} | ||
|
||
validator := gody.NewValidator() | ||
|
||
if err := validator.AddRules(rule.NotEmpty); err != nil { | ||
log.Println(err) | ||
return err | ||
} | ||
|
||
valid, err := validator.Validate(b) | ||
if err != nil { | ||
if !valid { | ||
log.Println("body do not validated:", err) | ||
} | ||
|
||
switch err.(type) { | ||
case *rule.ErrNotEmpty: | ||
log.Println("not empty error:", err) | ||
} | ||
} | ||
return err | ||
} |
This file contains hidden or 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,42 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
"github.com/guiferpa/gody/v2/rule" | ||
) | ||
|
||
|
||
// Test generated using Keploy | ||
func TestSimpleDefaultValidation_EmptyText(t *testing.T) { | ||
err := SimpleDefaultValidation("") | ||
if err == nil { | ||
t.Errorf("Expected error for empty Text, but got nil") | ||
} | ||
if _, ok := err.(*rule.ErrNotEmpty); !ok { | ||
t.Errorf("Expected ErrNotEmpty, but got %v", err) | ||
} | ||
} | ||
|
||
// Test generated using Keploy | ||
func TestSimplePureValidation_EmptyText(t *testing.T) { | ||
err := SimplePureValidation("") | ||
if err == nil { | ||
t.Errorf("Expected error for empty Text, but got nil") | ||
} | ||
if _, ok := err.(*rule.ErrNotEmpty); !ok { | ||
t.Errorf("Expected ErrNotEmpty, but got %v", err) | ||
} | ||
} | ||
|
||
|
||
// Test generated using Keploy | ||
func TestSimpleValidationFromValidator_EmptyText(t *testing.T) { | ||
err := SimpleValidationFromValidator("") | ||
if err == nil { | ||
t.Errorf("Expected error for empty Text, but got nil") | ||
} | ||
if _, ok := err.(*rule.ErrNotEmpty); !ok { | ||
t.Errorf("Expected ErrNotEmpty, but got %v", err) | ||
} | ||
} | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The messages of assert conditions are too much generics. It's not valuable when we're developing and need to run the tests.