mirror of
https://github.com/appleboy/drone-discord.git
synced 2026-06-04 18:33:47 +08:00
84ee42a6e4
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMissingConfig(t *testing.T) {
|
|
var plugin Plugin
|
|
|
|
err := plugin.Exec()
|
|
|
|
assert.NotNil(t, err)
|
|
}
|
|
|
|
func TestDefaultMessageFormat(t *testing.T) {
|
|
plugin := Plugin{
|
|
Repo: Repo{
|
|
Name: "go-hello",
|
|
Owner: "appleboy",
|
|
},
|
|
Build: Build{
|
|
Number: 101,
|
|
Status: "success",
|
|
Link: "https://github.com/appleboy/go-hello",
|
|
Author: "Bo-Yi Wu",
|
|
Branch: "master",
|
|
Message: "update by drone line plugin.",
|
|
Commit: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
|
|
},
|
|
}
|
|
|
|
message := plugin.Message(plugin.Repo, plugin.Build)
|
|
|
|
assert.Equal(t, []string{"[success] <https://github.com/appleboy/go-hello> (master)『update by drone line plugin.』by Bo-Yi Wu"}, message)
|
|
}
|
|
|
|
func TestErrorSendMessage(t *testing.T) {
|
|
plugin := Plugin{
|
|
Repo: Repo{
|
|
Name: "go-hello",
|
|
Owner: "appleboy",
|
|
},
|
|
Build: Build{
|
|
Number: 101,
|
|
Status: "success",
|
|
Link: "https://github.com/appleboy/go-hello",
|
|
Author: "Bo-Yi Wu",
|
|
Branch: "master",
|
|
Message: "update by drone discord plugin.",
|
|
Commit: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
|
|
},
|
|
|
|
Config: Config{
|
|
WebhookID: os.Getenv("WEBHOOK_ID"),
|
|
WebhookToken: os.Getenv("WEBHOOK_TOKEN"),
|
|
Wait: false,
|
|
Content: []string{"test one message from drone testing", "test two message from drone testing"},
|
|
Username: "drone-ci",
|
|
TTS: false,
|
|
},
|
|
}
|
|
|
|
err := plugin.Exec()
|
|
assert.Nil(t, err)
|
|
|
|
plugin.Config.Content = []string{}
|
|
err = plugin.Exec()
|
|
assert.Nil(t, err)
|
|
}
|