mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-07-01 03:30:49 +00:00
parent
4f8732bafc
commit
e74115027b
|
@ -1252,8 +1252,8 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"204": {
|
||||||
"description": "OK"
|
"description": "No Content"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1278,8 +1278,8 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"204": {
|
||||||
"description": "OK"
|
"description": "No Content"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1304,8 +1304,8 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"204": {
|
||||||
"description": "OK"
|
"description": "No Content"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2055,8 +2055,8 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"204": {
|
||||||
"description": "OK"
|
"description": "No Content"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,6 @@ func TestService(t *testing.T) {
|
||||||
|
|
||||||
s, _ := Service("foo", "bar", "baz", []string{"1", "2", "3"})
|
s, _ := Service("foo", "bar", "baz", []string{"1", "2", "3"})
|
||||||
j, err := json.Marshal(s)
|
j, err := json.Marshal(s)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.JSONEq(t, expected, string(j))
|
assert.JSONEq(t, expected, string(j))
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,19 +65,19 @@ func TestPersistentVolumeClaim(t *testing.T) {
|
||||||
}`
|
}`
|
||||||
|
|
||||||
pvc, err := PersistentVolumeClaim("someNamespace", "somename", "local-storage", "1Gi", true)
|
pvc, err := PersistentVolumeClaim("someNamespace", "somename", "local-storage", "1Gi", true)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
j, err := json.Marshal(pvc)
|
j, err := json.Marshal(pvc)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.JSONEq(t, expectedRwx, string(j))
|
assert.JSONEq(t, expectedRwx, string(j))
|
||||||
|
|
||||||
pvc, err = PersistentVolumeClaim("someNamespace", "somename", "local-storage", "1Gi", false)
|
pvc, err = PersistentVolumeClaim("someNamespace", "somename", "local-storage", "1Gi", false)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
j, err = json.Marshal(pvc)
|
j, err = json.Marshal(pvc)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.JSONEq(t, expectedRwo, string(j))
|
assert.JSONEq(t, expectedRwo, string(j))
|
||||||
|
|
||||||
_, err = PersistentVolumeClaim("someNamespace", "some0INVALID3name", "local-storage", "1Gi", false)
|
_, err = PersistentVolumeClaim("someNamespace", "some0INVALID3name", "local-storage", "1Gi", false)
|
||||||
assert.NotNil(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
33
pipeline/backend/local/const_test.go
Normal file
33
pipeline/backend/local/const_test.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright 2023 Woodpecker Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package local
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGenNetRC(t *testing.T) {
|
||||||
|
assert.Equal(t, `
|
||||||
|
machine machine
|
||||||
|
login user
|
||||||
|
password pass
|
||||||
|
`, genNetRC(map[string]string{
|
||||||
|
"CI_NETRC_MACHINE": "machine",
|
||||||
|
"CI_NETRC_USERNAME": "user",
|
||||||
|
"CI_NETRC_PASSWORD": "pass",
|
||||||
|
}))
|
||||||
|
}
|
|
@ -35,7 +35,7 @@ func TestStringorIntYaml(t *testing.T) {
|
||||||
assert.Equal(t, StringOrInt(10), s.Foo)
|
assert.Equal(t, StringOrInt(10), s.Foo)
|
||||||
|
|
||||||
d, err := yaml.Marshal(&s)
|
d, err := yaml.Marshal(&s)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
s2 := StructStringorInt{}
|
s2 := StructStringorInt{}
|
||||||
assert.NoError(t, yaml.Unmarshal(d, &s2))
|
assert.NoError(t, yaml.Unmarshal(d, &s2))
|
||||||
|
@ -57,7 +57,7 @@ func TestStringOrSliceYaml(t *testing.T) {
|
||||||
assert.Equal(t, StringOrSlice{"bar", "baz"}, s.Foo)
|
assert.Equal(t, StringOrSlice{"bar", "baz"}, s.Foo)
|
||||||
|
|
||||||
d, err := yaml.Marshal(&s)
|
d, err := yaml.Marshal(&s)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
s2 := StructStringOrSlice{}
|
s2 := StructStringOrSlice{}
|
||||||
assert.NoError(t, yaml.Unmarshal(d, &s2))
|
assert.NoError(t, yaml.Unmarshal(d, &s2))
|
||||||
|
@ -79,7 +79,7 @@ func TestSliceOrMapYaml(t *testing.T) {
|
||||||
assert.Equal(t, SliceOrMap{"bar": "baz", "far": "faz"}, s.Foos)
|
assert.Equal(t, SliceOrMap{"bar": "baz", "far": "faz"}, s.Foos)
|
||||||
|
|
||||||
d, err := yaml.Marshal(&s)
|
d, err := yaml.Marshal(&s)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
s2 := StructSliceorMap{}
|
s2 := StructSliceorMap{}
|
||||||
assert.NoError(t, yaml.Unmarshal(d, &s2))
|
assert.NoError(t, yaml.Unmarshal(d, &s2))
|
||||||
|
@ -106,7 +106,7 @@ func TestStr2SliceOrMapPtrMap(t *testing.T) {
|
||||||
Bars: []string{},
|
Bars: []string{},
|
||||||
}}
|
}}
|
||||||
d, err := yaml.Marshal(&s)
|
d, err := yaml.Marshal(&s)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
s2 := map[string]*StructSliceorMap{}
|
s2 := map[string]*StructSliceorMap{}
|
||||||
assert.NoError(t, yaml.Unmarshal(d, &s2))
|
assert.NoError(t, yaml.Unmarshal(d, &s2))
|
||||||
|
|
|
@ -91,7 +91,7 @@ network2:
|
||||||
}
|
}
|
||||||
for _, network := range networks {
|
for _, network := range networks {
|
||||||
bytes, err := yaml.Marshal(network.networks)
|
bytes, err := yaml.Marshal(network.networks)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, network.expected, string(bytes), "should be equal")
|
assert.Equal(t, network.expected, string(bytes), "should be equal")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ func TestMarshalVolumes(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, volume := range volumes {
|
for _, volume := range volumes {
|
||||||
bytes, err := yaml.Marshal(volume.volumes)
|
bytes, err := yaml.Marshal(volume.volumes)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, volume.expected, string(bytes), "should be equal")
|
assert.Equal(t, volume.expected, string(bytes), "should be equal")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ func TestUnmarshalVolumes(t *testing.T) {
|
||||||
for _, volume := range volumes {
|
for _, volume := range volumes {
|
||||||
actual := &Volumes{}
|
actual := &Volumes{}
|
||||||
err := yaml.Unmarshal([]byte(volume.yaml), actual)
|
err := yaml.Unmarshal([]byte(volume.yaml), actual)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, volume.expected, actual, "should be equal")
|
assert.Equal(t, volume.expected, actual, "should be equal")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.31.0
|
||||||
// protoc v4.23.4
|
// protoc v4.24.3
|
||||||
// source: woodpecker.proto
|
// source: woodpecker.proto
|
||||||
|
|
||||||
package proto
|
package proto
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.3.0
|
// - protoc-gen-go-grpc v1.3.0
|
||||||
// - protoc v4.23.4
|
// - protoc v4.24.3
|
||||||
// source: woodpecker.proto
|
// source: woodpecker.proto
|
||||||
|
|
||||||
package proto
|
package proto
|
||||||
|
|
|
@ -54,12 +54,12 @@ func GetQueueInfo(c *gin.Context) {
|
||||||
// @Summary Pause a pipeline queue
|
// @Summary Pause a pipeline queue
|
||||||
// @Router /queue/pause [post]
|
// @Router /queue/pause [post]
|
||||||
// @Produce plain
|
// @Produce plain
|
||||||
// @Success 200
|
// @Success 204
|
||||||
// @Tags Pipeline queues
|
// @Tags Pipeline queues
|
||||||
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
|
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
|
||||||
func PauseQueue(c *gin.Context) {
|
func PauseQueue(c *gin.Context) {
|
||||||
server.Config.Services.Queue.Pause()
|
server.Config.Services.Queue.Pause()
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResumeQueue
|
// ResumeQueue
|
||||||
|
@ -67,12 +67,12 @@ func PauseQueue(c *gin.Context) {
|
||||||
// @Summary Resume a pipeline queue
|
// @Summary Resume a pipeline queue
|
||||||
// @Router /queue/resume [post]
|
// @Router /queue/resume [post]
|
||||||
// @Produce plain
|
// @Produce plain
|
||||||
// @Success 200
|
// @Success 204
|
||||||
// @Tags Pipeline queues
|
// @Tags Pipeline queues
|
||||||
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
|
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
|
||||||
func ResumeQueue(c *gin.Context) {
|
func ResumeQueue(c *gin.Context) {
|
||||||
server.Config.Services.Queue.Resume()
|
server.Config.Services.Queue.Resume()
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockTilQueueHasRunningItem
|
// BlockTilQueueHasRunningItem
|
||||||
|
@ -80,7 +80,7 @@ func ResumeQueue(c *gin.Context) {
|
||||||
// @Summary Block til pipeline queue has a running item
|
// @Summary Block til pipeline queue has a running item
|
||||||
// @Router /queue/norunningpipelines [get]
|
// @Router /queue/norunningpipelines [get]
|
||||||
// @Produce plain
|
// @Produce plain
|
||||||
// @Success 200
|
// @Success 204
|
||||||
// @Tags Pipeline queues
|
// @Tags Pipeline queues
|
||||||
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
|
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
|
||||||
func BlockTilQueueHasRunningItem(c *gin.Context) {
|
func BlockTilQueueHasRunningItem(c *gin.Context) {
|
||||||
|
@ -90,7 +90,7 @@ func BlockTilQueueHasRunningItem(c *gin.Context) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostHook
|
// PostHook
|
||||||
|
|
|
@ -417,7 +417,7 @@ func RepairRepo(c *gin.Context) {
|
||||||
// @Summary Move a repository to a new owner
|
// @Summary Move a repository to a new owner
|
||||||
// @Router /repos/{repo_id}/move [post]
|
// @Router /repos/{repo_id}/move [post]
|
||||||
// @Produce plain
|
// @Produce plain
|
||||||
// @Success 200
|
// @Success 204
|
||||||
// @Tags Repositories
|
// @Tags Repositories
|
||||||
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
|
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
|
||||||
// @Param repo_id path int true "the repository id"
|
// @Param repo_id path int true "the repository id"
|
||||||
|
@ -493,7 +493,7 @@ func MoveRepo(c *gin.Context) {
|
||||||
c.String(http.StatusInternalServerError, err.Error())
|
c.String(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllRepos
|
// GetAllRepos
|
||||||
|
|
33
server/badges/badges_test.go
Normal file
33
server/badges/badges_test.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright 2022 Woodpecker Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package badges
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate an SVG badge based on a pipeline
|
||||||
|
func TestGenerate(t *testing.T) {
|
||||||
|
assert.Equal(t, badgeNone, Generate(nil))
|
||||||
|
assert.Equal(t, badgeSuccess, Generate(&model.Pipeline{Status: model.StatusSuccess}))
|
||||||
|
assert.Equal(t, badgeFailure, Generate(&model.Pipeline{Status: model.StatusFailure}))
|
||||||
|
assert.Equal(t, badgeError, Generate(&model.Pipeline{Status: model.StatusError}))
|
||||||
|
assert.Equal(t, badgeError, Generate(&model.Pipeline{Status: model.StatusKilled}))
|
||||||
|
assert.Equal(t, badgeStarted, Generate(&model.Pipeline{Status: model.StatusPending}))
|
||||||
|
assert.Equal(t, badgeStarted, Generate(&model.Pipeline{Status: model.StatusRunning}))
|
||||||
|
}
|
|
@ -96,9 +96,6 @@ func parsePushHook(hook *github.PushEvent) (*model.Repo, *model.Pipeline, error)
|
||||||
if len(pipeline.Author) == 0 {
|
if len(pipeline.Author) == 0 {
|
||||||
pipeline.Author = hook.GetHeadCommit().GetAuthor().GetLogin()
|
pipeline.Author = hook.GetHeadCommit().GetAuthor().GetLogin()
|
||||||
}
|
}
|
||||||
// if len(pipeline.Email) == 0 {
|
|
||||||
// TODO: default to gravatar?
|
|
||||||
// }
|
|
||||||
if strings.HasPrefix(pipeline.Ref, "refs/tags/") {
|
if strings.HasPrefix(pipeline.Ref, "refs/tags/") {
|
||||||
// just kidding, this is actually a tag event. Why did this come as a push
|
// just kidding, this is actually a tag event. Why did this come as a push
|
||||||
// event we'll never know!
|
// event we'll never know!
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Code generated by mockery v2.33.1. DO NOT EDIT.
|
// Code generated by mockery v2.36.0. DO NOT EDIT.
|
||||||
|
|
||||||
package mocks
|
package mocks
|
||||||
|
|
||||||
|
|
47
server/forge/types/meta_test.go
Normal file
47
server/forge/types/meta_test.go
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// Copyright 2023 Woodpecker Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSortByName(t *testing.T) {
|
||||||
|
fm := []*FileMeta{
|
||||||
|
{
|
||||||
|
Name: "a",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "c",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "b",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, []*FileMeta{
|
||||||
|
{
|
||||||
|
Name: "a",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "b",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "c",
|
||||||
|
},
|
||||||
|
}, SortByName(fm))
|
||||||
|
}
|
|
@ -23,7 +23,6 @@ type StepStore interface {
|
||||||
StepList(*Pipeline) ([]*Step, error)
|
StepList(*Pipeline) ([]*Step, error)
|
||||||
StepCreate([]*Step) error
|
StepCreate([]*Step) error
|
||||||
StepUpdate(*Step) error
|
StepUpdate(*Step) error
|
||||||
StepClear(*Pipeline) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Different ways to handle failure states
|
// Different ways to handle failure states
|
||||||
|
|
46
server/model/step_test.go
Normal file
46
server/model/step_test.go
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// Copyright 2023 Woodpecker Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStepStatus(t *testing.T) {
|
||||||
|
step := &Step{
|
||||||
|
State: StatusPending,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, step.Running(), true)
|
||||||
|
step.State = StatusRunning
|
||||||
|
assert.Equal(t, step.Running(), true)
|
||||||
|
|
||||||
|
step.Failure = FailureIgnore
|
||||||
|
step.State = StatusError
|
||||||
|
assert.Equal(t, step.Failing(), false)
|
||||||
|
step.State = StatusFailure
|
||||||
|
assert.Equal(t, step.Failing(), false)
|
||||||
|
step.Failure = FailureFail
|
||||||
|
step.State = StatusError
|
||||||
|
assert.Equal(t, step.Failing(), true)
|
||||||
|
step.State = StatusFailure
|
||||||
|
assert.Equal(t, step.Failing(), true)
|
||||||
|
step.State = StatusPending
|
||||||
|
assert.Equal(t, step.Failing(), false)
|
||||||
|
step.State = StatusSuccess
|
||||||
|
assert.Equal(t, step.Failing(), false)
|
||||||
|
}
|
|
@ -24,27 +24,27 @@ import (
|
||||||
func TestShortMessageLongKey(t *testing.T) {
|
func TestShortMessageLongKey(t *testing.T) {
|
||||||
aes := &aesEncryptionService{}
|
aes := &aesEncryptionService{}
|
||||||
err := aes.loadCipher(string(random.GetRandomBytes(32)))
|
err := aes.loadCipher(string(random.GetRandomBytes(32)))
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
input := string(random.GetRandomBytes(4))
|
input := string(random.GetRandomBytes(4))
|
||||||
cipher, err := aes.Encrypt(input, "")
|
cipher, err := aes.Encrypt(input, "")
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
output, err := aes.Decrypt(cipher, "")
|
output, err := aes.Decrypt(cipher, "")
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, input, output)
|
assert.Equal(t, input, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLongMessageShortKey(t *testing.T) {
|
func TestLongMessageShortKey(t *testing.T) {
|
||||||
aes := &aesEncryptionService{}
|
aes := &aesEncryptionService{}
|
||||||
err := aes.loadCipher(string(random.GetRandomBytes(12)))
|
err := aes.loadCipher(string(random.GetRandomBytes(12)))
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
input := string(random.GetRandomBytes(1024))
|
input := string(random.GetRandomBytes(1024))
|
||||||
cipher, err := aes.Encrypt(input, "")
|
cipher, err := aes.Encrypt(input, "")
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
output, err := aes.Decrypt(cipher, "")
|
output, err := aes.Decrypt(cipher, "")
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, input, output)
|
assert.Equal(t, input, output)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ package datastore
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,28 +31,62 @@ func TestAgentFindByToken(t *testing.T) {
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Token: "secret-token",
|
Token: "secret-token",
|
||||||
}
|
}
|
||||||
if err := store.AgentCreate(agent); err != nil {
|
err := store.AgentCreate(agent)
|
||||||
t.Errorf("Unexpected error: insert agent: %s", err)
|
assert.NoError(t, err)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_agent, err := store.AgentFindByToken(agent.Token)
|
_agent, err := store.AgentFindByToken(agent.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if got, want := _agent.ID, int64(1); got != want {
|
assert.Equal(t, int64(1), _agent.ID)
|
||||||
t.Errorf("Want config id %d, got %d", want, got)
|
|
||||||
}
|
|
||||||
|
|
||||||
_agent, err = store.AgentFindByToken("")
|
_agent, err = store.AgentFindByToken("")
|
||||||
if err == nil || err.Error() != "Please provide a token" {
|
assert.ErrorIs(t, err, ErrNoTokenProvided)
|
||||||
t.Errorf("Expected to get an error for an empty token, but got %s", err)
|
assert.Nil(t, _agent)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _agent != nil {
|
func TestAgentFindByID(t *testing.T) {
|
||||||
t.Errorf("Expected to not find an agent")
|
store, closer := newTestStore(t, new(model.Agent))
|
||||||
return
|
defer closer()
|
||||||
|
|
||||||
|
agent := &model.Agent{
|
||||||
|
ID: int64(1),
|
||||||
|
Name: "test",
|
||||||
|
Token: "secret-token",
|
||||||
}
|
}
|
||||||
|
err := store.AgentCreate(agent)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
_agent, err := store.AgentFind(agent.ID)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "secret-token", _agent.Token)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAgentList(t *testing.T) {
|
||||||
|
store, closer := newTestStore(t, new(model.Agent))
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
agent1 := &model.Agent{
|
||||||
|
ID: int64(1),
|
||||||
|
Name: "test-1",
|
||||||
|
Token: "secret-token-1",
|
||||||
|
}
|
||||||
|
agent2 := &model.Agent{
|
||||||
|
ID: int64(2),
|
||||||
|
Name: "test-2",
|
||||||
|
Token: "secret-token-2",
|
||||||
|
}
|
||||||
|
err := store.AgentCreate(agent1)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
err = store.AgentCreate(agent2)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
agents, err := store.AgentList(&model.ListOptions{All: true})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 2, len(agents))
|
||||||
|
|
||||||
|
agents, err = store.AgentList(&model.ListOptions{Page: 1, PerPage: 1})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 1, len(agents))
|
||||||
}
|
}
|
||||||
|
|
39
server/store/datastore/helper_test.go
Normal file
39
server/store/datastore/helper_test.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
// Copyright 2023 Woodpecker Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package datastore
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/store/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWrapGet(t *testing.T) {
|
||||||
|
err := wrapGet(false, nil)
|
||||||
|
assert.ErrorIs(t, err, types.RecordNotExist)
|
||||||
|
|
||||||
|
err = wrapGet(true, errors.New("test err"))
|
||||||
|
assert.Equal(t, "TestWrapGet: test err", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrapDelete(t *testing.T) {
|
||||||
|
err := wrapDelete(0, nil)
|
||||||
|
assert.ErrorIs(t, err, types.RecordNotExist)
|
||||||
|
|
||||||
|
err = wrapDelete(1, errors.New("test err"))
|
||||||
|
assert.Equal(t, "TestWrapDelete: test err", err.Error())
|
||||||
|
}
|
|
@ -43,7 +43,10 @@ func (s storage) ServerConfigSet(key, value string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.engine.Where("key = ?", config.Key).AllCols().Update(config)
|
// TODO change to Where() when https://gitea.com/xorm/xorm/issues/2358 is solved
|
||||||
|
_, err = s.engine.Cols("value").Update(config, &model.ServerConfig{
|
||||||
|
Key: key,
|
||||||
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,4 +43,31 @@ func TestServerConfigGetSet(t *testing.T) {
|
||||||
t.Errorf("Want server-config value %s, got %s", serverConfig.Value, value)
|
t.Errorf("Want server-config value %s, got %s", serverConfig.Value, value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serverConfig.Value = "new-wonderland"
|
||||||
|
if err := store.ServerConfigSet(serverConfig.Key, serverConfig.Value); err != nil {
|
||||||
|
t.Errorf("Unexpected error: insert secret: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err = store.ServerConfigGet(serverConfig.Key)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: delete secret: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if value != serverConfig.Value {
|
||||||
|
t.Errorf("Want server-config value %s, got %s", serverConfig.Value, value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err = store.ServerConfigGet("config_not_exist")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Unexpected: no error on missing config: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if value != "" {
|
||||||
|
t.Errorf("Unexpected: got value on missing config: %s", value)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,24 +83,6 @@ func (s storage) StepUpdate(step *model.Step) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s storage) StepClear(pipeline *model.Pipeline) error {
|
|
||||||
sess := s.engine.NewSession()
|
|
||||||
defer sess.Close()
|
|
||||||
if err := sess.Begin(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := sess.Where("step_pipeline_id = ?", pipeline.ID).Delete(new(model.Step)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := sess.Where("workflow_pipeline_id = ?", pipeline.ID).Delete(new(model.Workflow)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return sess.Commit()
|
|
||||||
}
|
|
||||||
|
|
||||||
func deleteStep(sess *xorm.Session, stepID int64) error {
|
func deleteStep(sess *xorm.Session, stepID int64) error {
|
||||||
if _, err := sess.Where("step_id = ?", stepID).Delete(new(model.LogEntry)); err != nil {
|
if _, err := sess.Where("step_id = ?", stepID).Delete(new(model.LogEntry)); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -246,4 +246,39 @@ func TestStepByUUID(t *testing.T) {
|
||||||
assert.Empty(t, step)
|
assert.Empty(t, step)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: func TestStepCascade(t *testing.T) {}
|
func TestStepLoad(t *testing.T) {
|
||||||
|
store, closer := newTestStore(t, new(model.Step))
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
sess := store.engine.NewSession()
|
||||||
|
assert.NoError(t, store.stepCreate(sess, []*model.Step{
|
||||||
|
{
|
||||||
|
UUID: "4db7e5fc-5312-4d02-9e14-b51b9e3242cc",
|
||||||
|
PipelineID: 1,
|
||||||
|
PID: 1,
|
||||||
|
PPID: 1,
|
||||||
|
State: "running",
|
||||||
|
Name: "build",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UUID: "fc7c7fd6-553e-480b-8ed7-30d8563d0b79",
|
||||||
|
PipelineID: 4,
|
||||||
|
PID: 6,
|
||||||
|
PPID: 7,
|
||||||
|
Name: "build",
|
||||||
|
State: "pending",
|
||||||
|
Error: "pc load letter",
|
||||||
|
ExitCode: 255,
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
_ = sess.Close()
|
||||||
|
|
||||||
|
step, err := store.StepLoad(1)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotEmpty(t, step)
|
||||||
|
assert.Equal(t, step.UUID, "4db7e5fc-5312-4d02-9e14-b51b9e3242cc")
|
||||||
|
|
||||||
|
step, err = store.StepLoad(5)
|
||||||
|
assert.ErrorIs(t, err, types.RecordNotExist)
|
||||||
|
assert.Empty(t, step)
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Code generated by mockery v2.33.1. DO NOT EDIT.
|
// Code generated by mockery v2.36.0. DO NOT EDIT.
|
||||||
|
|
||||||
package mocks
|
package mocks
|
||||||
|
|
||||||
|
@ -1859,20 +1859,6 @@ func (_m *Store) StepChild(_a0 *model.Pipeline, _a1 int, _a2 string) (*model.Ste
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// StepClear provides a mock function with given fields: _a0
|
|
||||||
func (_m *Store) StepClear(_a0 *model.Pipeline) error {
|
|
||||||
ret := _m.Called(_a0)
|
|
||||||
|
|
||||||
var r0 error
|
|
||||||
if rf, ok := ret.Get(0).(func(*model.Pipeline) error); ok {
|
|
||||||
r0 = rf(_a0)
|
|
||||||
} else {
|
|
||||||
r0 = ret.Error(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r0
|
|
||||||
}
|
|
||||||
|
|
||||||
// StepFind provides a mock function with given fields: _a0, _a1
|
// StepFind provides a mock function with given fields: _a0, _a1
|
||||||
func (_m *Store) StepFind(_a0 *model.Pipeline, _a1 int) (*model.Step, error) {
|
func (_m *Store) StepFind(_a0 *model.Pipeline, _a1 int) (*model.Step, error) {
|
||||||
ret := _m.Called(_a0, _a1)
|
ret := _m.Called(_a0, _a1)
|
||||||
|
|
|
@ -141,7 +141,6 @@ type Store interface {
|
||||||
StepChild(*model.Pipeline, int, string) (*model.Step, error)
|
StepChild(*model.Pipeline, int, string) (*model.Step, error)
|
||||||
StepList(*model.Pipeline) ([]*model.Step, error)
|
StepList(*model.Pipeline) ([]*model.Step, error)
|
||||||
StepUpdate(*model.Step) error
|
StepUpdate(*model.Step) error
|
||||||
StepClear(*model.Pipeline) error
|
|
||||||
StepListFromWorkflowFind(*model.Workflow) ([]*model.Step, error)
|
StepListFromWorkflowFind(*model.Workflow) ([]*model.Step, error)
|
||||||
|
|
||||||
// Logs
|
// Logs
|
||||||
|
|
Loading…
Reference in a new issue