artmigrator/repository/nexus/nexus_mock.go

36 lines
917 B
Go

// nexus_mock.go
package nexus
import (
"net/http"
"net/http/httptest"
"github.com/stretchr/testify/mock"
)
type MockClient struct {
mock.Mock
Server *httptest.Server
}
func NewMockClient() *MockClient {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Здесь мы можем определить логику для обработки запросов
w.WriteHeader(200)
w.Write([]byte("artifact1\nartifact2\n"))
}))
return &MockClient{
Server: server,
}
}
func (m *MockClient) GetArtifacts(repository string) ([]string, error) {
args := m.Called(repository)
return args.Get(0).([]string), args.Error(1)
}
func (m *MockClient) GetArtifactData(repository, artifact string) ([]byte, error) {
args := m.Called(repository, artifact)
return args.Get(0).([]byte), args.Error(1)
}