From c48accfb518dab0305dd935d9663724399b9c1d6 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 5 Sep 2025 15:03:52 +0200 Subject: [PATCH] chore: cache: generate mocks for act/artifactcache/caches.go --- Makefile | 4 +- act/artifactcache/caches.go | 1 + act/artifactcache/mock_caches.go | 230 ++++++++++++++++++++++++++++ internal/pkg/client/mocks/Client.go | 2 +- 4 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 act/artifactcache/mock_caches.go diff --git a/Makefile b/Makefile index 1b4890ec..06029b7f 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ else endif endif -GO_PACKAGES_TO_VET ?= $(filter-out code.forgejo.org/forgejo/runner/v11/internal/pkg/client/mocks,$(shell $(GO) list ./...)) +GO_PACKAGES_TO_VET ?= $(filter-out code.forgejo.org/forgejo/runner/v11/internal/pkg/client/mocks code.forgejo.org/forgejo/runner/v11/act/artifactcache/mock_caches.go,$(shell $(GO) list ./...)) TAGS ?= LDFLAGS ?= -X "code.forgejo.org/forgejo/runner/v11/internal/pkg/ver.version=v$(RELEASE_VERSION)" @@ -120,7 +120,7 @@ vet: .PHONY: generate generate: - $(GO) generate ./internal/... + $(GO) generate ./... install: $(GOFILES) $(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' diff --git a/act/artifactcache/caches.go b/act/artifactcache/caches.go index 014a6011..16b3204d 100644 --- a/act/artifactcache/caches.go +++ b/act/artifactcache/caches.go @@ -17,6 +17,7 @@ import ( "go.etcd.io/bbolt" ) +//go:generate mockery --inpackage --name caches type caches interface { openDB() (*bolthold.Store, error) validateMac(rundata RunData) (string, error) diff --git a/act/artifactcache/mock_caches.go b/act/artifactcache/mock_caches.go new file mode 100644 index 00000000..9d484f80 --- /dev/null +++ b/act/artifactcache/mock_caches.go @@ -0,0 +1,230 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package artifactcache + +import ( + http "net/http" + + bolthold "github.com/timshannon/bolthold" + + io "io" + + mock "github.com/stretchr/testify/mock" + + time "time" +) + +// mockCaches is an autogenerated mock type for the caches type +type mockCaches struct { + mock.Mock +} + +// commit provides a mock function with given fields: id, size +func (_m *mockCaches) commit(id uint64, size int64) (int64, error) { + ret := _m.Called(id, size) + + if len(ret) == 0 { + panic("no return value specified for commit") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(uint64, int64) (int64, error)); ok { + return rf(id, size) + } + if rf, ok := ret.Get(0).(func(uint64, int64) int64); ok { + r0 = rf(id, size) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(uint64, int64) error); ok { + r1 = rf(id, size) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// exist provides a mock function with given fields: id +func (_m *mockCaches) exist(id uint64) (bool, error) { + ret := _m.Called(id) + + if len(ret) == 0 { + panic("no return value specified for exist") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(uint64) (bool, error)); ok { + return rf(id) + } + if rf, ok := ret.Get(0).(func(uint64) bool); ok { + r0 = rf(id) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(uint64) error); ok { + r1 = rf(id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// gcCache provides a mock function with no fields +func (_m *mockCaches) gcCache() { + _m.Called() +} + +// openDB provides a mock function with no fields +func (_m *mockCaches) openDB() (*bolthold.Store, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for openDB") + } + + var r0 *bolthold.Store + var r1 error + if rf, ok := ret.Get(0).(func() (*bolthold.Store, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *bolthold.Store); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*bolthold.Store) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// readCache provides a mock function with given fields: id, repo +func (_m *mockCaches) readCache(id uint64, repo string) (*Cache, error) { + ret := _m.Called(id, repo) + + if len(ret) == 0 { + panic("no return value specified for readCache") + } + + var r0 *Cache + var r1 error + if rf, ok := ret.Get(0).(func(uint64, string) (*Cache, error)); ok { + return rf(id, repo) + } + if rf, ok := ret.Get(0).(func(uint64, string) *Cache); ok { + r0 = rf(id, repo) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*Cache) + } + } + + if rf, ok := ret.Get(1).(func(uint64, string) error); ok { + r1 = rf(id, repo) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// serve provides a mock function with given fields: w, r, id +func (_m *mockCaches) serve(w http.ResponseWriter, r *http.Request, id uint64) { + _m.Called(w, r, id) +} + +// setgcAt provides a mock function with given fields: at +func (_m *mockCaches) setgcAt(at time.Time) { + _m.Called(at) +} + +// useCache provides a mock function with given fields: id +func (_m *mockCaches) useCache(id uint64) error { + ret := _m.Called(id) + + if len(ret) == 0 { + panic("no return value specified for useCache") + } + + var r0 error + if rf, ok := ret.Get(0).(func(uint64) error); ok { + r0 = rf(id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// validateMac provides a mock function with given fields: rundata +func (_m *mockCaches) validateMac(rundata RunData) (string, error) { + ret := _m.Called(rundata) + + if len(ret) == 0 { + panic("no return value specified for validateMac") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(RunData) (string, error)); ok { + return rf(rundata) + } + if rf, ok := ret.Get(0).(func(RunData) string); ok { + r0 = rf(rundata) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(RunData) error); ok { + r1 = rf(rundata) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// write provides a mock function with given fields: id, offset, reader +func (_m *mockCaches) write(id uint64, offset uint64, reader io.Reader) error { + ret := _m.Called(id, offset, reader) + + if len(ret) == 0 { + panic("no return value specified for write") + } + + var r0 error + if rf, ok := ret.Get(0).(func(uint64, uint64, io.Reader) error); ok { + r0 = rf(id, offset, reader) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// newMockCaches creates a new instance of mockCaches. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockCaches(t interface { + mock.TestingT + Cleanup(func()) +}, +) *mockCaches { + mock := &mockCaches{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/pkg/client/mocks/Client.go b/internal/pkg/client/mocks/Client.go index f2ea5fe2..3b3ab6cb 100644 --- a/internal/pkg/client/mocks/Client.go +++ b/internal/pkg/client/mocks/Client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.53.4. DO NOT EDIT. +// Code generated by mockery v2.53.5. DO NOT EDIT. package mocks