Fix can't call duration helper func (#104)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2021-07-03 12:39:54 +08:00
committed by GitHub
parent 882afee629
commit ca270b33c8
4 changed files with 33 additions and 4 deletions
+29
View File
@@ -5,6 +5,7 @@ import (
"testing"
"time"
"github.com/appleboy/drone-template-lib/template"
"github.com/stretchr/testify/assert"
)
@@ -497,3 +498,31 @@ func TestProxySendMessage(t *testing.T) {
err := plugin.Exec()
assert.Nil(t, err)
}
func TestBuildTemplate(t *testing.T) {
plugin := Plugin{
Commit: Commit{
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Author: "Bo-Yi Wu",
Branch: "master",
Message: "This is a test commit msg",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
Started: time.Now().Unix(),
Finished: time.Now().Add(time.Duration(180 * time.Second)).Unix(),
},
}
_, err := template.RenderTrim(
`
Sample message loaded from file.
Commit msg: {{uppercasefirst commit.message}}
duration: {{duration build.started build.finished}}
`, plugin)
assert.Nil(t, err)
}