1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-12 08:23:48 +02:00
woodpecker/server/remote/common/status_test.go

36 lines
1.2 KiB
Go
Raw Normal View History

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))
}