未验证 提交 53143481 编写于 作者: S SampsonYe(叶飞) 提交者: GitHub

Merge pull request #104 from fanhousanbu/issue-90-unittest

Issue 90 unittest
name: Test and coverage
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Run coverage
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
run: bash <(curl -s https://codecov.io/bash)
......@@ -47,6 +47,7 @@ require (
github.com/google/uuid v1.2.0 // indirect
github.com/gorilla/websocket v1.4.2
github.com/isbrick/tools v0.0.0-20211027093338-a3a0ded37175
github.com/jarcoal/httpmock v1.1.0
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pborman/uuid v1.2.0
......
# notification config
[notification]
dingEnable = 1
ding = "https://dingtalk.unittest.com"
mailEnable = 1
smtpHost = "smtp.host"
smtpPort = 465
smtpAccount = "fake@mail.com"
smtpPassword = "pwd"
\ No newline at end of file
package main
import (
"github.com/astaxie/beego"
notification "github.com/go-atomci/atomci/internal/core/notification/impl"
messages "github.com/go-atomci/atomci/internal/core/notification/types"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
func init() {
beego.LoadAppConfig("ini", "./app.unittest.conf")
}
func Test_SEND_SHOULD_NO_ERROR(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("POST", "https://dingtalk.unittest.com",
func(req *http.Request) (*http.Response, error) {
resp, err := httpmock.NewJsonResponse(200, "")
if err != nil {
return httpmock.NewStringResponse(500, ""), nil
}
return resp, nil
},
)
var temp notification.INotify
mockResult := new(messages.StepCallbackResult)
temp = new(notification.Email)
assert.NoError(t, temp.Send(*mockResult))
temp = new(notification.DingRobot)
assert.NoError(t, temp.Send(*mockResult))
hit := httpmock.GetTotalCallCount()
assert.Equal(t, 1, hit)
}
package notification
import (
notification "github.com/go-atomci/atomci/internal/core/notification/impl"
messages "github.com/go-atomci/atomci/internal/core/notification/types"
"testing"
)
func TestNotifyEmail(t *testing.T) {
notification.EmailHandler().Send(messages.StepCallbackResult{
StageName: "",
PublishName: "",
StepName: "",
Status: 1,
})
}
func TestNotifyDingRobot(t *testing.T) {
notification.DingRobotHandler().Send(messages.StepCallbackResult{
StageName: "aa",
PublishName: "bb",
StepName: "cc",
Status: 0,
})
}
......@@ -26,4 +26,4 @@ func TestGetStatus(t *testing.T) {
t.Run("jenkins", func(t *testing.T) {
assert.Nil(t, nil)
})
}
}
\ No newline at end of file
......@@ -219,6 +219,9 @@ func initOrm() {
// Init ...
func init() {
if len(os.Args) > 1 && os.Args[1][:5] == "-test" {
return
}
initOrm()
// orm.RunSyncdb("default", false, true)
}
......@@ -8,7 +8,7 @@ import (
)
func TestAesCrypto(t *testing.T) {
crypted := base64.StdEncoding.EncodeToString(AesEny([]byte("Hello")))
log.Printf("%s", crypted)
assert.NotEmpty(t, crypted)
encrypted := base64.StdEncoding.EncodeToString(AesEny([]byte("Hello")))
log.Printf("%s", encrypted)
assert.NotEmpty(t, encrypted)
}
package utils
import (
"github.com/stretchr/testify/assert"
"testing"
)
func Test_NEWUUID_SHOULD_NOT_EMPTY(t *testing.T) {
uuid := NewUUID()
assert.NotEmpty(t, uuid)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册