diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 37e98692c..0a9c40dee 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -1252,8 +1252,8 @@ const docTemplate = `{ } ], "responses": { - "200": { - "description": "OK" + "204": { + "description": "No Content" } } } @@ -1278,8 +1278,8 @@ const docTemplate = `{ } ], "responses": { - "200": { - "description": "OK" + "204": { + "description": "No Content" } } } @@ -1304,8 +1304,8 @@ const docTemplate = `{ } ], "responses": { - "200": { - "description": "OK" + "204": { + "description": "No Content" } } } @@ -2055,8 +2055,8 @@ const docTemplate = `{ } ], "responses": { - "200": { - "description": "OK" + "204": { + "description": "No Content" } } } diff --git a/pipeline/backend/kubernetes/service_test.go b/pipeline/backend/kubernetes/service_test.go index 6702b36d5..2d0441d3b 100644 --- a/pipeline/backend/kubernetes/service_test.go +++ b/pipeline/backend/kubernetes/service_test.go @@ -56,6 +56,6 @@ func TestService(t *testing.T) { s, _ := Service("foo", "bar", "baz", []string{"1", "2", "3"}) j, err := json.Marshal(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.JSONEq(t, expected, string(j)) } diff --git a/pipeline/backend/kubernetes/volume_test.go b/pipeline/backend/kubernetes/volume_test.go index d1132c46f..fb38a6825 100644 --- a/pipeline/backend/kubernetes/volume_test.go +++ b/pipeline/backend/kubernetes/volume_test.go @@ -65,19 +65,19 @@ func TestPersistentVolumeClaim(t *testing.T) { }` pvc, err := PersistentVolumeClaim("someNamespace", "somename", "local-storage", "1Gi", true) - assert.Nil(t, err) + assert.NoError(t, err) j, err := json.Marshal(pvc) - assert.Nil(t, err) + assert.NoError(t, err) assert.JSONEq(t, expectedRwx, string(j)) pvc, err = PersistentVolumeClaim("someNamespace", "somename", "local-storage", "1Gi", false) - assert.Nil(t, err) + assert.NoError(t, err) j, err = json.Marshal(pvc) - assert.Nil(t, err) + assert.NoError(t, err) assert.JSONEq(t, expectedRwo, string(j)) _, err = PersistentVolumeClaim("someNamespace", "some0INVALID3name", "local-storage", "1Gi", false) - assert.NotNil(t, err) + assert.Error(t, err) } diff --git a/pipeline/backend/local/const_test.go b/pipeline/backend/local/const_test.go new file mode 100644 index 000000000..9ca9af4bd --- /dev/null +++ b/pipeline/backend/local/const_test.go @@ -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", + })) +} diff --git a/pipeline/frontend/yaml/types/base/base_types_test.go b/pipeline/frontend/yaml/types/base/base_types_test.go index 244b82667..98accdfab 100644 --- a/pipeline/frontend/yaml/types/base/base_types_test.go +++ b/pipeline/frontend/yaml/types/base/base_types_test.go @@ -35,7 +35,7 @@ func TestStringorIntYaml(t *testing.T) { assert.Equal(t, StringOrInt(10), s.Foo) d, err := yaml.Marshal(&s) - assert.Nil(t, err) + assert.NoError(t, err) s2 := StructStringorInt{} assert.NoError(t, yaml.Unmarshal(d, &s2)) @@ -57,7 +57,7 @@ func TestStringOrSliceYaml(t *testing.T) { assert.Equal(t, StringOrSlice{"bar", "baz"}, s.Foo) d, err := yaml.Marshal(&s) - assert.Nil(t, err) + assert.NoError(t, err) s2 := StructStringOrSlice{} 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) d, err := yaml.Marshal(&s) - assert.Nil(t, err) + assert.NoError(t, err) s2 := StructSliceorMap{} assert.NoError(t, yaml.Unmarshal(d, &s2)) @@ -106,7 +106,7 @@ func TestStr2SliceOrMapPtrMap(t *testing.T) { Bars: []string{}, }} d, err := yaml.Marshal(&s) - assert.Nil(t, err) + assert.NoError(t, err) s2 := map[string]*StructSliceorMap{} assert.NoError(t, yaml.Unmarshal(d, &s2)) diff --git a/pipeline/frontend/yaml/types/network_test.go b/pipeline/frontend/yaml/types/network_test.go index 96d720f6d..bdb09bf9e 100644 --- a/pipeline/frontend/yaml/types/network_test.go +++ b/pipeline/frontend/yaml/types/network_test.go @@ -91,7 +91,7 @@ network2: } for _, network := range 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") } } diff --git a/pipeline/frontend/yaml/types/volume_test.go b/pipeline/frontend/yaml/types/volume_test.go index ad536b2da..07270b1a4 100644 --- a/pipeline/frontend/yaml/types/volume_test.go +++ b/pipeline/frontend/yaml/types/volume_test.go @@ -88,7 +88,7 @@ func TestMarshalVolumes(t *testing.T) { } for _, volume := range 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") } } @@ -151,7 +151,7 @@ func TestUnmarshalVolumes(t *testing.T) { for _, volume := range volumes { actual := &Volumes{} err := yaml.Unmarshal([]byte(volume.yaml), actual) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, volume.expected, actual, "should be equal") } } diff --git a/pipeline/rpc/proto/woodpecker.pb.go b/pipeline/rpc/proto/woodpecker.pb.go index 0fead4b8e..332fb8e8d 100644 --- a/pipeline/rpc/proto/woodpecker.pb.go +++ b/pipeline/rpc/proto/woodpecker.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v4.23.4 +// protoc v4.24.3 // source: woodpecker.proto package proto diff --git a/pipeline/rpc/proto/woodpecker_grpc.pb.go b/pipeline/rpc/proto/woodpecker_grpc.pb.go index b6f0f6ae1..b3c5a2005 100644 --- a/pipeline/rpc/proto/woodpecker_grpc.pb.go +++ b/pipeline/rpc/proto/woodpecker_grpc.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.23.4 +// - protoc v4.24.3 // source: woodpecker.proto package proto diff --git a/server/api/hook.go b/server/api/hook.go index b2fab9725..534d515f0 100644 --- a/server/api/hook.go +++ b/server/api/hook.go @@ -54,12 +54,12 @@ func GetQueueInfo(c *gin.Context) { // @Summary Pause a pipeline queue // @Router /queue/pause [post] // @Produce plain -// @Success 200 +// @Success 204 // @Tags Pipeline queues // @Param Authorization header string true "Insert your personal access token" default(Bearer ) func PauseQueue(c *gin.Context) { server.Config.Services.Queue.Pause() - c.Status(http.StatusOK) + c.Status(http.StatusNoContent) } // ResumeQueue @@ -67,12 +67,12 @@ func PauseQueue(c *gin.Context) { // @Summary Resume a pipeline queue // @Router /queue/resume [post] // @Produce plain -// @Success 200 +// @Success 204 // @Tags Pipeline queues // @Param Authorization header string true "Insert your personal access token" default(Bearer ) func ResumeQueue(c *gin.Context) { server.Config.Services.Queue.Resume() - c.Status(http.StatusOK) + c.Status(http.StatusNoContent) } // BlockTilQueueHasRunningItem @@ -80,7 +80,7 @@ func ResumeQueue(c *gin.Context) { // @Summary Block til pipeline queue has a running item // @Router /queue/norunningpipelines [get] // @Produce plain -// @Success 200 +// @Success 204 // @Tags Pipeline queues // @Param Authorization header string true "Insert your personal access token" default(Bearer ) func BlockTilQueueHasRunningItem(c *gin.Context) { @@ -90,7 +90,7 @@ func BlockTilQueueHasRunningItem(c *gin.Context) { break } } - c.Status(http.StatusOK) + c.Status(http.StatusNoContent) } // PostHook diff --git a/server/api/repo.go b/server/api/repo.go index 6586e1917..7c262eef1 100644 --- a/server/api/repo.go +++ b/server/api/repo.go @@ -417,7 +417,7 @@ func RepairRepo(c *gin.Context) { // @Summary Move a repository to a new owner // @Router /repos/{repo_id}/move [post] // @Produce plain -// @Success 200 +// @Success 204 // @Tags Repositories // @Param Authorization header string true "Insert your personal access token" default(Bearer ) // @Param repo_id path int true "the repository id" @@ -493,7 +493,7 @@ func MoveRepo(c *gin.Context) { c.String(http.StatusInternalServerError, err.Error()) return } - c.Status(http.StatusOK) + c.Status(http.StatusNoContent) } // GetAllRepos diff --git a/server/badges/badges_test.go b/server/badges/badges_test.go new file mode 100644 index 000000000..fc7f1a1c6 --- /dev/null +++ b/server/badges/badges_test.go @@ -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})) +} diff --git a/server/forge/github/parse.go b/server/forge/github/parse.go index 4311a7188..f49af8c81 100644 --- a/server/forge/github/parse.go +++ b/server/forge/github/parse.go @@ -96,9 +96,6 @@ func parsePushHook(hook *github.PushEvent) (*model.Repo, *model.Pipeline, error) if len(pipeline.Author) == 0 { pipeline.Author = hook.GetHeadCommit().GetAuthor().GetLogin() } - // if len(pipeline.Email) == 0 { - // TODO: default to gravatar? - // } if strings.HasPrefix(pipeline.Ref, "refs/tags/") { // just kidding, this is actually a tag event. Why did this come as a push // event we'll never know! diff --git a/server/forge/mocks/forge.go b/server/forge/mocks/forge.go index 2d9f544f3..8be5e48e1 100644 --- a/server/forge/mocks/forge.go +++ b/server/forge/mocks/forge.go @@ -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 diff --git a/server/forge/types/meta_test.go b/server/forge/types/meta_test.go new file mode 100644 index 000000000..071607ea3 --- /dev/null +++ b/server/forge/types/meta_test.go @@ -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)) +} diff --git a/server/model/step.go b/server/model/step.go index edf40e611..5341a7cd6 100644 --- a/server/model/step.go +++ b/server/model/step.go @@ -23,7 +23,6 @@ type StepStore interface { StepList(*Pipeline) ([]*Step, error) StepCreate([]*Step) error StepUpdate(*Step) error - StepClear(*Pipeline) error } // Different ways to handle failure states diff --git a/server/model/step_test.go b/server/model/step_test.go new file mode 100644 index 000000000..0f8df8650 --- /dev/null +++ b/server/model/step_test.go @@ -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) +} diff --git a/server/plugins/encryption/aes_test.go b/server/plugins/encryption/aes_test.go index 658f178c6..1a2bc5abb 100644 --- a/server/plugins/encryption/aes_test.go +++ b/server/plugins/encryption/aes_test.go @@ -24,27 +24,27 @@ import ( func TestShortMessageLongKey(t *testing.T) { aes := &aesEncryptionService{} err := aes.loadCipher(string(random.GetRandomBytes(32))) - assert.Nil(t, err) + assert.NoError(t, err) input := string(random.GetRandomBytes(4)) cipher, err := aes.Encrypt(input, "") - assert.Nil(t, err) + assert.NoError(t, err) output, err := aes.Decrypt(cipher, "") - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, input, output) } func TestLongMessageShortKey(t *testing.T) { aes := &aesEncryptionService{} err := aes.loadCipher(string(random.GetRandomBytes(12))) - assert.Nil(t, err) + assert.NoError(t, err) input := string(random.GetRandomBytes(1024)) cipher, err := aes.Encrypt(input, "") - assert.Nil(t, err) + assert.NoError(t, err) output, err := aes.Decrypt(cipher, "") - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, input, output) } diff --git a/server/store/datastore/agent_test.go b/server/store/datastore/agent_test.go index 6ba037f2c..47bb0cc8e 100644 --- a/server/store/datastore/agent_test.go +++ b/server/store/datastore/agent_test.go @@ -17,6 +17,8 @@ package datastore import ( "testing" + "github.com/stretchr/testify/assert" + "github.com/woodpecker-ci/woodpecker/server/model" ) @@ -29,28 +31,62 @@ func TestAgentFindByToken(t *testing.T) { Name: "test", Token: "secret-token", } - if err := store.AgentCreate(agent); err != nil { - t.Errorf("Unexpected error: insert agent: %s", err) - return - } + err := store.AgentCreate(agent) + assert.NoError(t, err) _agent, err := store.AgentFindByToken(agent.Token) if err != nil { t.Error(err) return } - if got, want := _agent.ID, int64(1); got != want { - t.Errorf("Want config id %d, got %d", want, got) - } + assert.Equal(t, int64(1), _agent.ID) _agent, err = store.AgentFindByToken("") - if err == nil || err.Error() != "Please provide a token" { - t.Errorf("Expected to get an error for an empty token, but got %s", err) - return - } - - if _agent != nil { - t.Errorf("Expected to not find an agent") - return - } + assert.ErrorIs(t, err, ErrNoTokenProvided) + assert.Nil(t, _agent) +} + +func TestAgentFindByID(t *testing.T) { + store, closer := newTestStore(t, new(model.Agent)) + 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)) } diff --git a/server/store/datastore/helper_test.go b/server/store/datastore/helper_test.go new file mode 100644 index 000000000..ba47fb5ea --- /dev/null +++ b/server/store/datastore/helper_test.go @@ -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()) +} diff --git a/server/store/datastore/server_config.go b/server/store/datastore/server_config.go index c6afed79c..6e1eee1d6 100644 --- a/server/store/datastore/server_config.go +++ b/server/store/datastore/server_config.go @@ -43,7 +43,10 @@ func (s storage) ServerConfigSet(key, value string) error { 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 } diff --git a/server/store/datastore/server_config_test.go b/server/store/datastore/server_config_test.go index 04d6e2f48..a6ff025ed 100644 --- a/server/store/datastore/server_config_test.go +++ b/server/store/datastore/server_config_test.go @@ -43,4 +43,31 @@ func TestServerConfigGetSet(t *testing.T) { t.Errorf("Want server-config value %s, got %s", serverConfig.Value, value) 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 + } } diff --git a/server/store/datastore/step.go b/server/store/datastore/step.go index 6ef3e0bfb..902939c5e 100644 --- a/server/store/datastore/step.go +++ b/server/store/datastore/step.go @@ -83,24 +83,6 @@ func (s storage) StepUpdate(step *model.Step) error { 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 { if _, err := sess.Where("step_id = ?", stepID).Delete(new(model.LogEntry)); err != nil { return err diff --git a/server/store/datastore/step_test.go b/server/store/datastore/step_test.go index 3fd385969..53e22a459 100644 --- a/server/store/datastore/step_test.go +++ b/server/store/datastore/step_test.go @@ -246,4 +246,39 @@ func TestStepByUUID(t *testing.T) { 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) +} diff --git a/server/store/mocks/store.go b/server/store/mocks/store.go index 5d3c58ffc..88d88ba24 100644 --- a/server/store/mocks/store.go +++ b/server/store/mocks/store.go @@ -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 @@ -1859,20 +1859,6 @@ func (_m *Store) StepChild(_a0 *model.Pipeline, _a1 int, _a2 string) (*model.Ste 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 func (_m *Store) StepFind(_a0 *model.Pipeline, _a1 int) (*model.Step, error) { ret := _m.Called(_a0, _a1) diff --git a/server/store/store.go b/server/store/store.go index 42aa95129..113d50db1 100644 --- a/server/store/store.go +++ b/server/store/store.go @@ -141,7 +141,6 @@ type Store interface { StepChild(*model.Pipeline, int, string) (*model.Step, error) StepList(*model.Pipeline) ([]*model.Step, error) StepUpdate(*model.Step) error - StepClear(*model.Pipeline) error StepListFromWorkflowFind(*model.Workflow) ([]*model.Step, error) // Logs