woodpecker/server/remote/common/status_test.go
qwerty287 6568751320
Allow to change forge status messages (#900)
Allow to change the status message via template option

Closes https://github.com/woodpecker-ci/woodpecker/issues/855
2022-05-12 19:07:33 +02:00

35 lines
1.2 KiB
Go

package common
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/woodpecker-ci/woodpecker/server"
"github.com/woodpecker-ci/woodpecker/server/model"
)
func TestGetBuildStatusContext(t *testing.T) {
origFormat := server.Config.Server.StatusContextFormat
origCtx := server.Config.Server.StatusContext
defer func() {
server.Config.Server.StatusContextFormat = origFormat
server.Config.Server.StatusContext = origCtx
}()
repo := &model.Repo{Owner: "user1", Name: "repo1"}
build := &model.Build{Event: model.EventPull}
proc := &model.Proc{Name: "lint"}
assert.EqualValues(t, "", GetBuildStatusContext(repo, build, proc))
server.Config.Server.StatusContext = "ci/woodpecker"
server.Config.Server.StatusContextFormat = "{{ .context }}/{{ .event }}/{{ .pipeline }}"
assert.EqualValues(t, "ci/woodpecker/pr/lint", GetBuildStatusContext(repo, build, proc))
build.Event = model.EventPush
assert.EqualValues(t, "ci/woodpecker/push/lint", GetBuildStatusContext(repo, build, proc))
server.Config.Server.StatusContext = "ci"
server.Config.Server.StatusContextFormat = "{{ .context }}:{{ .owner }}/{{ .repo }}:{{ .event }}:{{ .pipeline }}"
assert.EqualValues(t, "ci:user1/repo1:push:lint", GetBuildStatusContext(repo, build, proc))
}