-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support to run tests with multiple threads (#13)
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
- Loading branch information
1 parent
7c4f12c
commit 8564fc1
Showing
10 changed files
with
147 additions
and
33 deletions.
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
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
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
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
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
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,2 @@ | ||
// Package render provides a simple way to render as template | ||
package render |
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,21 @@ | ||
package render | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
"strings" | ||
|
||
"github.com/Masterminds/sprig/v3" | ||
) | ||
|
||
// Render render then return the result | ||
func Render(name, text string, ctx interface{}) (result string, err error) { | ||
var tpl *template.Template | ||
if tpl, err = template.New(name).Funcs(sprig.FuncMap()).Parse(text); err == nil { | ||
buf := new(bytes.Buffer) | ||
if err = tpl.Execute(buf, ctx); err == nil { | ||
result = strings.TrimSpace(buf.String()) | ||
} | ||
} | ||
return | ||
} |
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,33 @@ | ||
package render | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRender(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
text string | ||
ctx interface{} | ||
expect string | ||
}{{ | ||
name: "default", | ||
text: `{{default "hello" .Bar}}`, | ||
ctx: nil, | ||
expect: "hello", | ||
}, { | ||
name: "trim", | ||
text: `{{trim " hello "}}`, | ||
ctx: "", | ||
expect: "hello", | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result, err := Render(tt.name, tt.text, tt.ctx) | ||
assert.Nil(t, err) | ||
assert.Equal(t, tt.expect, 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
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