Skip to content

Commit

Permalink
chore: somes clean
Browse files Browse the repository at this point in the history
  • Loading branch information
42atomys committed Sep 2, 2024
1 parent 14b9c54 commit 270cae4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions registry/backward/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestUrlParse(t *testing.T) {
{Input: `{{ urlParse "https://example.com" | urlJoin }}`, ExpectedOutput: "https://example.com"},
{Input: `{{ urlParse "https://example.com/path" | urlJoin }}`, ExpectedOutput: "https://example.com/path"},
{Input: `{{ urlParse "https://user:pass@example.com/path?query=1" | urlJoin }}`, ExpectedOutput: "https://user:pass@example.com/path?query=1"},
{Input: `{{ urlParse "://" }}`, ExpectedErr: "unable to parse url"},
}

pesticide.RunTestCases(t, backward.NewRegistry(), tc)
Expand Down
11 changes: 7 additions & 4 deletions registry/random/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ func (rr *RandomRegistry) RandNumeric(count int) string {
// Example:
//
// {{ 16 | randBytes }} // Output: "c3RhY2thYnVzZSByb2NrcyE=" (output will vary)
func (rr *RandomRegistry) RandBytes(count int) string {
func (rr *RandomRegistry) RandBytes(count int) (string, error) {
if count <= 0 {
return ""
return "", nil
}

buf := make([]byte, count)
_, _ = cryptorand.Read(buf)
return base64.StdEncoding.EncodeToString(buf)
_, err := cryptorand.Read(buf)
if err != nil {
return "", err
}

Check warning on line 99 in registry/random/functions.go

View check run for this annotation

Codecov / codecov/patch

registry/random/functions.go#L98-L99

Added lines #L98 - L99 were not covered by tests
return base64.StdEncoding.EncodeToString(buf), nil
}

// RandInt generates a random integer between the specified minimum and maximum
Expand Down
2 changes: 1 addition & 1 deletion registry/reflect/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
//
// {{ "int", 42 | typeIs }} // Output: true
func (rr *ReflectRegistry) TypeIs(target string, src any) bool {
return rr.TypeOf(src) == target
return target == rr.TypeOf(src)
}

// TypeIsLike compares the type of 'src' to a target type string 'target',
Expand Down

0 comments on commit 270cae4

Please sign in to comment.