You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Factory is used to obtain new instances of Repo.
typeFactoryinterface {
// New returns a new instance of Repo for the supplied URL.
//
// If the project can not be found, the error NoRepoFound will be returned.
//
// If the project is not valid for use, or there is any other issue creating
// the Repo, Repo will be nil and an error will be returned.
New(context.Context, *url.URL) (Repo, error)
// Match returns true if this factory can create a new instance of Repo
// repository for the given repository URL.
Match(*url.URL) bool
}
Here is what mockgen created:
// Code generated by MockGen. DO NOT EDIT.// Source: internal/collector/projectrepo/repo.go// Package mocks is a generated GoMock package.package mocks
import (
context "context"
gomock "github.com/golang/mock/gomock""github.com/ossf/criticality_score/internal/collector/projectrepo"
url "net/url"
reflect "reflect"
)
// MockRepo is a mock of Repo interface.typeMockRepostruct {
ctrl*gomock.Controllerrecorder*MockRepoMockRecorder
}
// MockRepoMockRecorder is the mock recorder for MockRepo.typeMockRepoMockRecorderstruct {
mock*MockRepo
}
// NewMockRepo creates a new mock instance.funcNewMockRepo(ctrl*gomock.Controller) *MockRepo {
mock:=&MockRepo{ctrl: ctrl}
mock.recorder=&MockRepoMockRecorder{mock}
returnmock
}
// EXPECT returns an object that allows the caller to indicate expected use.func (m*MockRepo) EXPECT() *MockRepoMockRecorder {
returnm.recorder
}
// URL mocks base method.func (m*MockRepo) URL() *url.URL {
m.ctrl.T.Helper()
ret:=m.ctrl.Call(m, "URL")
ret0, _:=ret[0].(*url.URL)
returnret0
}
// URL indicates an expected call of URL.func (mr*MockRepoMockRecorder) URL() *gomock.Call {
mr.mock.ctrl.T.Helper()
returnmr.mock.ctrl.RecordCallWithMethodType(mr.mock, "URL", reflect.TypeOf((*MockRepo)(nil).URL))
}
// MockFactory is a mock of Factory interface.typeMockFactorystruct {
ctrl*gomock.Controllerrecorder*MockFactoryMockRecorder
}
// MockFactoryMockRecorder is the mock recorder for MockFactory.typeMockFactoryMockRecorderstruct {
mock*MockFactory
}
// NewMockFactory creates a new mock instance.funcNewMockFactory(ctrl*gomock.Controller) *MockFactory {
mock:=&MockFactory{ctrl: ctrl}
mock.recorder=&MockFactoryMockRecorder{mock}
returnmock
}
// EXPECT returns an object that allows the caller to indicate expected use.func (m*MockFactory) EXPECT() *MockFactoryMockRecorder {
returnm.recorder
}
// Match mocks base method.func (m*MockFactory) Match(arg0*url.URL) bool {
m.ctrl.T.Helper()
ret:=m.ctrl.Call(m, "Match", arg0)
ret0, _:=ret[0].(bool)
returnret0
}
// Match indicates an expected call of Match.func (mr*MockFactoryMockRecorder) Match(arg0interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
returnmr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Match", reflect.TypeOf((*MockFactory)(nil).Match), arg0)
}
// New mocks base method.func (m*MockFactory) New(arg0 context.Context, arg1*url.URL) (projectrepo.Repo, error) {
m.ctrl.T.Helper()
ret:=m.ctrl.Call(m, "New", arg0, arg1)
ret0, _:=ret[0].(projectrepo.Repo)
ret1, _:=ret[1].(error)
returnret0, ret1
}
// New indicates an expected call of New.func (mr*MockFactoryMockRecorder) New(arg0, arg1interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
returnmr.mock.ctrl.RecordCallWithMethodType(mr.mock, "New", reflect.TypeOf((*MockFactory)(nil).New), arg0, arg1)
}
The Issue:
The mock is using the projectrepo package and my test (which is inside projectrepo) is calling the mock package. This causes an import cycle error:
package github.com/ossf/criticality_score/internal/collector/projectrepo
imports github.com/ossf/criticality_score/internal/mocks: import cycle not allowed in test
Plausible Solution:
My suggestion would be to move repo.go into a separate package within the collector package. This is similar to collector/signal/source#277.
The text was updated successfully, but these errors were encountered:
I am in the process of creating tests for
internal/collector/projectrepo/resolver
. I was trying to createmocks
forrepo
:criticality_score/internal/collector/projectrepo/repo.go
Lines 23 to 40 in 95942e0
Here is what mockgen created:
The Issue:
The mock is using the
projectrepo
package and my test (which is insideprojectrepo
) is calling the mock package. This causes an import cycle error:Plausible Solution:
My suggestion would be to move
repo.go
into a separate package within thecollector
package. This is similar tocollector/signal/source
#277.The text was updated successfully, but these errors were encountered: