Best Mock code snippet using source.NewMockS
auth_proxy_test.go
Source:auth_proxy_test.go
1package authproxy2import (3 "context"4 "errors"5 "net/http"6 "net/url"7 "testing"8 "time"9 "github.com/golang/mock/gomock"10 "github.com/int128/kauthproxy/pkg/browser/mock_browser"11 "github.com/int128/kauthproxy/pkg/env/mock_env"12 "github.com/int128/kauthproxy/pkg/logger/mock_logger"13 "github.com/int128/kauthproxy/pkg/portforwarder"14 "github.com/int128/kauthproxy/pkg/portforwarder/mock_portforwarder"15 "github.com/int128/kauthproxy/pkg/resolver/mock_resolver"16 "github.com/int128/kauthproxy/pkg/reverseproxy"17 "github.com/int128/kauthproxy/pkg/reverseproxy/mock_reverseproxy"18 "github.com/int128/kauthproxy/pkg/transport"19 v1 "k8s.io/api/core/v1"20 v1meta "k8s.io/apimachinery/pkg/apis/meta/v1"21 "k8s.io/client-go/rest"22)23var notNil = gomock.Not(gomock.Nil())24var restConfig rest.Config25var authProxyTransport http.Transport26func newTransport(t *testing.T) transport.NewFunc {27 return func(got *rest.Config) (http.RoundTripper, error) {28 if got != &restConfig {29 t.Errorf("rest.Config mismatch, got %+v", got)30 }31 return &authProxyTransport, nil32 }33}34func TestAuthProxy_Do(t *testing.T) {35 const containerPort = 1888836 const transitPort = 2888837 pod := &v1.Pod{38 ObjectMeta: v1meta.ObjectMeta{39 Name: "kubernetes-dashboard-12345678-12345678",40 Namespace: "kubernetes-dashboard",41 },42 }43 t.Run("ToPod", func(t *testing.T) {44 type mocks struct {45 resolverFactory *mock_resolver.MockFactoryInterface46 env *mock_env.MockInterface47 browser *mock_browser.MockInterface48 }49 newMocks := func(ctrl *gomock.Controller) mocks {50 m := mocks{51 resolverFactory: mock_resolver.NewMockFactoryInterface(ctrl),52 env: mock_env.NewMockInterface(ctrl),53 browser: mock_browser.NewMockInterface(ctrl),54 }55 m.env.EXPECT().56 AllocateLocalPort().57 Return(transitPort, nil)58 mockResolver := mock_resolver.NewMockInterface(ctrl)59 mockResolver.EXPECT().60 FindPodByName(gomock.Any(), "NAMESPACE", "podname").61 Return(pod, containerPort, nil)62 m.resolverFactory.EXPECT().63 New(&restConfig).64 Return(mockResolver, nil)65 return m66 }67 t.Run("Success", func(t *testing.T) {68 ctx, cancel := context.WithTimeout(context.TODO(), 500*time.Millisecond)69 defer cancel()70 ctrl := gomock.NewController(t)71 defer ctrl.Finish()72 portForwarder := mock_portforwarder.NewMockInterface(ctrl)73 portForwarder.EXPECT().74 Run(portforwarder.Option{75 Config: &restConfig,76 SourcePort: transitPort,77 TargetNamespace: "kubernetes-dashboard",78 TargetPodName: "kubernetes-dashboard-12345678-12345678",79 TargetContainerPort: containerPort,80 }, notNil, notNil).81 DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {82 time.Sleep(100 * time.Millisecond)83 close(readyChan)84 <-stopChan85 return nil86 })87 reverseProxy := mock_reverseproxy.NewMockInterface(ctrl)88 reverseProxy.EXPECT().89 Run(reverseproxy.Option{90 Transport: &authProxyTransport,91 BindAddressCandidates: []string{"127.0.0.1:8000"},92 TargetScheme: "https",93 TargetHost: "localhost",94 TargetPort: transitPort,95 }, notNil).96 DoAndReturn(func(o reverseproxy.Option, readyChan chan<- reverseproxy.Instance) error {97 time.Sleep(100 * time.Millisecond)98 i := mock_reverseproxy.NewMockInstance(ctrl)99 i.EXPECT().100 URL().101 Return(&url.URL{Scheme: "http", Host: "localhost:8000"})102 i.EXPECT().103 Shutdown(notNil).104 Return(nil)105 readyChan <- i106 return nil107 })108 m := newMocks(ctrl)109 m.browser.EXPECT().Open("http://localhost:8000")110 u := &AuthProxy{111 ReverseProxy: reverseProxy,112 PortForwarder: portForwarder,113 ResolverFactory: m.resolverFactory,114 NewTransport: newTransport(t),115 Env: m.env,116 Browser: m.browser,117 Logger: mock_logger.New(t),118 }119 o := Option{120 Config: &restConfig,121 Namespace: "NAMESPACE",122 TargetURL: parseURL(t, "https://podname"),123 BindAddressCandidates: []string{"127.0.0.1:8000"},124 }125 err := u.Do(ctx, o)126 if !errors.Is(err, context.DeadlineExceeded) {127 t.Errorf("err wants context.DeadlineExceeded but was %+v", err)128 }129 })130 t.Run("PortForwarderError", func(t *testing.T) {131 ctx := context.TODO()132 ctrl := gomock.NewController(t)133 defer ctrl.Finish()134 portForwarderError := errors.New("could not connect to pod")135 portForwarder := mock_portforwarder.NewMockInterface(ctrl)136 portForwarder.EXPECT().137 Run(portforwarder.Option{138 Config: &restConfig,139 SourcePort: transitPort,140 TargetNamespace: "kubernetes-dashboard",141 TargetPodName: "kubernetes-dashboard-12345678-12345678",142 TargetContainerPort: containerPort,143 }, notNil, notNil).144 DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {145 return portForwarderError146 })147 reverseProxy := mock_reverseproxy.NewMockInterface(ctrl)148 m := newMocks(ctrl)149 u := &AuthProxy{150 ReverseProxy: reverseProxy,151 PortForwarder: portForwarder,152 ResolverFactory: m.resolverFactory,153 NewTransport: newTransport(t),154 Env: m.env,155 Browser: m.browser,156 Logger: mock_logger.New(t),157 }158 o := Option{159 Config: &restConfig,160 Namespace: "NAMESPACE",161 TargetURL: parseURL(t, "https://podname"),162 BindAddressCandidates: []string{"127.0.0.1:8000"},163 }164 err := u.Do(ctx, o)165 if !errors.Is(err, portForwarderError) {166 t.Errorf("err wants the port forwarder error but was %+v", err)167 }168 })169 t.Run("ReverseProxyError", func(t *testing.T) {170 ctx := context.TODO()171 ctrl := gomock.NewController(t)172 defer ctrl.Finish()173 portForwarder := mock_portforwarder.NewMockInterface(ctrl)174 portForwarder.EXPECT().175 Run(portforwarder.Option{176 Config: &restConfig,177 SourcePort: transitPort,178 TargetNamespace: "kubernetes-dashboard",179 TargetPodName: "kubernetes-dashboard-12345678-12345678",180 TargetContainerPort: containerPort,181 }, notNil, notNil).182 DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {183 time.Sleep(100 * time.Millisecond)184 close(readyChan)185 <-stopChan186 return nil187 })188 reverseProxyError := errors.New("could not listen")189 reverseProxy := mock_reverseproxy.NewMockInterface(ctrl)190 reverseProxy.EXPECT().191 Run(reverseproxy.Option{192 Transport: &authProxyTransport,193 BindAddressCandidates: []string{"127.0.0.1:8000"},194 TargetScheme: "https",195 TargetHost: "localhost",196 TargetPort: transitPort,197 }, notNil).198 DoAndReturn(func(o reverseproxy.Option, readyChan chan<- reverseproxy.Instance) error {199 return reverseProxyError200 })201 m := newMocks(ctrl)202 u := &AuthProxy{203 ReverseProxy: reverseProxy,204 PortForwarder: portForwarder,205 ResolverFactory: m.resolverFactory,206 NewTransport: newTransport(t),207 Env: m.env,208 Browser: m.browser,209 Logger: mock_logger.New(t),210 }211 o := Option{212 Config: &restConfig,213 Namespace: "NAMESPACE",214 TargetURL: parseURL(t, "https://podname"),215 BindAddressCandidates: []string{"127.0.0.1:8000"},216 }217 err := u.Do(ctx, o)218 if !errors.Is(err, reverseProxyError) {219 t.Errorf("err wants the port forwarder error but was %+v", err)220 }221 })222 t.Run("PortForwarderConnectionLost", func(t *testing.T) {223 // 0ms: starting224 // 100ms: the port forwarder is ready225 // 200ms: the reverse proxy is ready226 // 400ms: lost connection227 // 900ms: retrying (after the backoff 500ms)228 // 1000ms: the port forwarder is ready229 // 1100ms: the reverse proxy is ready230 // 1200ms: cancel the context231 ctx, cancel := context.WithTimeout(context.TODO(), 1200*time.Millisecond)232 defer cancel()233 ctrl := gomock.NewController(t)234 defer ctrl.Finish()235 portForwarder := mock_portforwarder.NewMockInterface(ctrl)236 portForwarder.EXPECT().237 Run(portforwarder.Option{238 Config: &restConfig,239 SourcePort: transitPort,240 TargetNamespace: "kubernetes-dashboard",241 TargetPodName: "kubernetes-dashboard-12345678-12345678",242 TargetContainerPort: containerPort,243 }, notNil, notNil).244 DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {245 time.Sleep(100 * time.Millisecond)246 close(readyChan)247 time.Sleep(300 * time.Millisecond)248 return nil // lost connection249 }).250 Times(2)251 reverseProxy := mock_reverseproxy.NewMockInterface(ctrl)252 reverseProxy.EXPECT().253 Run(reverseproxy.Option{254 Transport: &authProxyTransport,255 BindAddressCandidates: []string{"127.0.0.1:8000"},256 TargetScheme: "https",257 TargetHost: "localhost",258 TargetPort: transitPort,259 }, notNil).260 DoAndReturn(func(o reverseproxy.Option, readyChan chan<- reverseproxy.Instance) error {261 time.Sleep(100 * time.Millisecond)262 i := mock_reverseproxy.NewMockInstance(ctrl)263 i.EXPECT().264 URL().265 Return(&url.URL{Scheme: "http", Host: "localhost:8000"})266 i.EXPECT().267 Shutdown(notNil).268 Return(nil)269 readyChan <- i270 return nil271 }).272 Times(2)273 m := newMocks(ctrl)274 m.browser.EXPECT().Open("http://localhost:8000")275 u := &AuthProxy{276 ReverseProxy: reverseProxy,277 PortForwarder: portForwarder,278 ResolverFactory: m.resolverFactory,279 NewTransport: newTransport(t),280 Env: m.env,281 Browser: m.browser,282 Logger: mock_logger.New(t),283 }284 o := Option{285 Config: &restConfig,286 Namespace: "NAMESPACE",287 TargetURL: parseURL(t, "https://podname"),288 BindAddressCandidates: []string{"127.0.0.1:8000"},289 }290 err := u.Do(ctx, o)291 if !errors.Is(err, context.DeadlineExceeded) {292 t.Errorf("err wants context.DeadlineExceeded but was %+v", err)293 }294 })295 })296 t.Run("ToService", func(t *testing.T) {297 type mocks struct {298 resolverFactory *mock_resolver.MockFactoryInterface299 env *mock_env.MockInterface300 browser *mock_browser.MockInterface301 }302 newMocks := func(ctrl *gomock.Controller) mocks {303 m := mocks{304 resolverFactory: mock_resolver.NewMockFactoryInterface(ctrl),305 env: mock_env.NewMockInterface(ctrl),306 browser: mock_browser.NewMockInterface(ctrl),307 }308 m.env.EXPECT().309 AllocateLocalPort().310 Return(transitPort, nil)311 mockResolver := mock_resolver.NewMockInterface(ctrl)312 mockResolver.EXPECT().313 FindPodByServiceName(gomock.Any(), "NAMESPACE", "servicename").314 Return(pod, containerPort, nil)315 m.resolverFactory.EXPECT().316 New(&restConfig).317 Return(mockResolver, nil)318 return m319 }320 t.Run("Success", func(t *testing.T) {321 ctx, cancel := context.WithTimeout(context.TODO(), 500*time.Millisecond)322 defer cancel()323 ctrl := gomock.NewController(t)324 defer ctrl.Finish()325 portForwarder := mock_portforwarder.NewMockInterface(ctrl)326 portForwarder.EXPECT().327 Run(portforwarder.Option{328 Config: &restConfig,329 SourcePort: transitPort,330 TargetNamespace: "kubernetes-dashboard",331 TargetPodName: "kubernetes-dashboard-12345678-12345678",332 TargetContainerPort: containerPort,333 }, notNil, notNil).334 DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {335 time.Sleep(100 * time.Millisecond)336 close(readyChan)337 <-stopChan338 return nil339 })340 reverseProxyInstance := mock_reverseproxy.NewMockInstance(ctrl)341 reverseProxyInstance.EXPECT().342 URL().343 Return(&url.URL{Scheme: "http", Host: "localhost:8000"})344 reverseProxyInstance.EXPECT().345 Shutdown(notNil).346 Return(nil)347 reverseProxy := mock_reverseproxy.NewMockInterface(ctrl)348 reverseProxy.EXPECT().349 Run(reverseproxy.Option{350 Transport: &authProxyTransport,351 BindAddressCandidates: []string{"127.0.0.1:8000"},352 TargetScheme: "https",353 TargetHost: "localhost",354 TargetPort: transitPort,355 }, notNil).356 DoAndReturn(func(o reverseproxy.Option, readyChan chan<- reverseproxy.Instance) error {357 time.Sleep(100 * time.Millisecond)358 readyChan <- reverseProxyInstance359 return nil360 })361 m := newMocks(ctrl)362 m.browser.EXPECT().Open("http://localhost:8000")363 u := &AuthProxy{364 ReverseProxy: reverseProxy,365 PortForwarder: portForwarder,366 ResolverFactory: m.resolverFactory,367 NewTransport: newTransport(t),368 Env: m.env,369 Browser: m.browser,370 Logger: mock_logger.New(t),371 }372 o := Option{373 Config: &restConfig,374 Namespace: "NAMESPACE",375 TargetURL: parseURL(t, "https://servicename.svc"),376 BindAddressCandidates: []string{"127.0.0.1:8000"},377 }378 err := u.Do(ctx, o)379 if !errors.Is(err, context.DeadlineExceeded) {380 t.Errorf("err wants context.DeadlineExceeded but was %+v", err)381 }382 })383 })384}385func parseURL(t *testing.T, s string) *url.URL {386 u, err := url.Parse(s)387 if err != nil {388 t.Errorf("could not parse URL: %s", err)389 }390 return u391}...
downloader_test.go
Source:downloader_test.go
1package get2import (3 "archive/zip"4 "bytes"5 "testing"6 "time"7 "github.com/stretchr/testify/require"8 "oss.indeed.com/go/modprox/pkg/clients/zips"9 "oss.indeed.com/go/modprox/pkg/coordinates"10 "oss.indeed.com/go/modprox/pkg/metrics/stats"11 "oss.indeed.com/go/modprox/pkg/repository"12 "oss.indeed.com/go/modprox/pkg/upstream"13 "oss.indeed.com/go/modprox/proxy/internal/modules/store"14)15type mocks struct {16 resolver *upstream.ResolverMock17 proxyClient *zips.ProxyClientMock18 upstreamClient *zips.UpstreamClientMock19 zipStore *store.ZipStoreMock20 index *store.IndexMock21 emitter *stats.SenderMock22}23func (m mocks) assertions() {24 m.proxyClient.MinimockFinish()25 m.upstreamClient.MinimockFinish()26 m.resolver.MinimockFinish()27 m.zipStore.MinimockFinish()28 m.index.MinimockFinish()29 m.emitter.MinimockFinish()30}31func newMocks(t *testing.T) mocks {32 return mocks{33 proxyClient: zips.NewProxyClientMock(t),34 upstreamClient: zips.NewUpstreamClientMock(t),35 resolver: upstream.NewResolverMock(t),36 zipStore: store.NewZipStoreMock(t),37 index: store.NewIndexMock(t),38 emitter: stats.NewSenderMock(t),39 }40}41func dummyZip(t *testing.T) repository.Blob {42 buf := new(bytes.Buffer)43 zipper := zip.NewWriter(buf)44 var files = []struct {45 Name string46 Body string47 }{48 {49 Name: "stuff/README.txt",50 Body: "this is a readme file",51 },52 {53 Name: "stuff/foo.go",54 Body: "package foo",55 },56 }57 for _, file := range files {58 f, err := zipper.Create(file.Name)59 require.NoError(t, err)60 _, err = f.Write([]byte(file.Body))61 require.NoError(t, err)62 }63 err := zipper.Close()64 require.NoError(t, err)65 return repository.Blob(buf.Bytes())66}67func Test_Download_upstream_ok(t *testing.T) {68 mocks := newMocks(t)69 defer mocks.assertions()70 serialModule := coordinates.SerialModule{71 Module: coordinates.Module{72 Source: "github.com/pkg/errors",73 Version: "v1.2.3",74 },75 SerialID: 16,76 }77 upstreamRequest := &upstream.Request{78 Transport: "https",79 Domain: "github.com",80 Namespace: []string{"pkg", "errors"},81 Version: "v1.2.3",82 }83 originalBlob := dummyZip(t)84 rewrittenBlob, err := zips.Rewrite(serialModule.Module, originalBlob)85 require.NoError(t, err)86 // force this module to be requested from upstream, not from global proxy87 mocks.resolver.UseProxyMock.When(serialModule.Module).Then(false, nil)88 // since we're going upstream, need to resolve the request89 mocks.resolver.ResolveMock.When(serialModule.Module).Then(upstreamRequest, nil)90 // return the original raw archive blob from upstream91 mocks.upstreamClient.GetMock.When(upstreamRequest).Then(originalBlob, nil)92 mocks.emitter.GaugeMSMock.Set(func(metric string, now time.Time) {93 require.Equal(t, "download-mod-elapsed-ms", metric)94 _ = now // ignore95 })96 mocks.zipStore.PutZipMock.When(serialModule.Module, rewrittenBlob).Then(nil)97 mocks.index.PutMock.When(store.ModuleAddition{98 Mod: serialModule.Module,99 UniqueID: 16,100 ModFile: "module github.com/pkg/errors\n",101 }).Then(nil)102 dl := New(103 mocks.proxyClient,104 mocks.upstreamClient,105 mocks.resolver,106 mocks.zipStore,107 mocks.index,108 mocks.emitter,109 )110 err = dl.Download(serialModule)111 require.NoError(t, err)112}113func Test_Download_proxy_ok(t *testing.T) {114 mocks := newMocks(t)115 defer mocks.assertions()116 serialModule := coordinates.SerialModule{117 Module: coordinates.Module{118 Source: "github.com/pkg/errors",119 Version: "v1.2.3",120 },121 SerialID: 16,122 }123 // when downloading from a proxy, the blob is already a well-formed zip124 originalBlob, err := zips.Rewrite(serialModule.Module, dummyZip(t))125 require.NoError(t, err)126 // allow this module to be requested from a global proxy127 mocks.resolver.UseProxyMock.When(serialModule.Module).Then(true, nil)128 // return the well-formed zip in response129 mocks.proxyClient.GetMock.When(serialModule.Module).Then(originalBlob, nil)130 mocks.emitter.GaugeMSMock.Set(func(metric string, now time.Time) {131 require.Equal(t, "download-mod-elapsed-ms", metric)132 _ = now // ignore133 })134 mocks.zipStore.PutZipMock.When(serialModule.Module, originalBlob).Then(nil)135 mocks.index.PutMock.When(store.ModuleAddition{136 Mod: serialModule.Module,137 UniqueID: 16,138 ModFile: "module github.com/pkg/errors\n",139 }).Then(nil)140 dl := New(141 mocks.proxyClient,142 mocks.upstreamClient,143 mocks.resolver,144 mocks.zipStore,145 mocks.index,146 mocks.emitter,147 )148 err = dl.Download(serialModule)149 require.NoError(t, err)150}151/*152func Test_Download_err_Resolve(t *testing.T) {153 mocks := newMocks()154 defer mocks.assertions(t)155 serialModule := coordinates.SerialModule{156 Module: coordinates.Module{157 Source: "github.com/pkg/errors",158 Version: "v1.2.3",159 },160 SerialID: 16,161 }162 upstreamRequest := &upstream.Request{163 Transport: "https",164 Domain: "github.com",165 Namespace: []string{"pkg", "errors"},166 Version: "v1.2.3",167 }168 // originalBlob := dummyZip(t)169 // rewrittenBlob, err := zips.Rewrite(serialMod.Module, originalBlob)170 // require.NoError(t, err)171 //mocks.resolver.On("Resolve", serialModule.Module).Return(172 // upstreamRequest, nil,173 //).Once()174 //175 //mocks.upstreamClient.On("Get", upstreamRequest).Return(176 // nil, errors.New("zip client get failed"),177 //).Once()178 dl := New(179 mocks.upstreamClient,180 mocks.resolver,181 mocks.zipStore,182 mocks.index,183 mocks.emitter,184 )185 err := dl.Download(serialModule)186 require.EqualError(t, err, "zip client get failed")187}188func Test_Download_err_Get(t *testing.T) {189 mocks := newMocks()190 defer mocks.assertions(t)191 serialModule := coordinates.SerialModule{192 Module: coordinates.Module{193 Source: "broken",194 Version: "broken",195 },196 SerialID: 0,197 }198 //mocks.resolver.On("Resolve", serialModule.Module).Return(199 // nil, errors.New("error on resolve"),200 //).Once()201 dl := New(202 mocks.upstreamClient,203 mocks.resolver,204 mocks.zipStore,205 mocks.index,206 mocks.emitter,207 )208 err := dl.Download(serialModule)209 require.EqualError(t, err, "error on resolve")210}211func Test_Download_err_Rewrite(t *testing.T) {212 mocks := newMocks()213 defer mocks.assertions(t)214 serialModule := coordinates.SerialModule{215 Module: coordinates.Module{216 Source: "broken",217 Version: "broken",218 },219 SerialID: 0,220 }221 upstreamRequest := &upstream.Request{222 Transport: "https",223 Domain: "github.com",224 Namespace: []string{"pkg", "errors"},225 Version: "v1.2.3",226 }227 // will cause zip rewrite failure (not valid zip file)228 badBlob := repository.Blob([]byte{1, 2, 3, 4})229 //mocks.resolver.On("Resolve", serialModule.Module).Return(230 // upstreamRequest, nil,231 //).Once()232 //233 //mocks.upstreamClient.On("Get", upstreamRequest).Return(234 // badBlob, nil,235 //).Once()236 //237 //mocks.emitter.On("GaugeMS",238 // "download-mod-elapsed-ms", mock.AnythingOfType("time.Time"),239 //).Once()240 dl := New(241 mocks.upstreamClient,242 mocks.resolver,243 mocks.zipStore,244 mocks.index,245 mocks.emitter,246 )247 err := dl.Download(serialModule)248 require.EqualError(t, err, "zip: not a valid zip file")249}250func Test_Download_err_PutZip(t *testing.T) {251 mocks := newMocks()252 defer mocks.assertions(t)253 serialModule := coordinates.SerialModule{254 Module: coordinates.Module{255 Source: "github.com/pkg/errors",256 Version: "v1.2.3",257 },258 SerialID: 16,259 }260 upstreamRequest := &upstream.Request{261 Transport: "https",262 Domain: "github.com",263 Namespace: []string{"pkg", "errors"},264 Version: "v1.2.3",265 }266 originalBlob := dummyZip(t)267 rewrittenBlob, err := zips.Rewrite(serialModule.Module, originalBlob)268 require.NoError(t, err)269 mocks.resolver.On("Resolve", serialModule.Module).Return(270 upstreamRequest, nil,271 ).Once()272 mocks.upstreamClient.On("Get", upstreamRequest).Return(273 originalBlob, nil,274 ).Once()275 mocks.emitter.On("GaugeMS",276 "download-mod-elapsed-ms", mock.AnythingOfType("time.Time"),277 ).Once()278 mocks.zipStore.On("PutZip",279 serialModule.Module,280 rewrittenBlob,281 ).Return(errors.New("put zip failure")).Once()282 dl := New(283 mocks.upstreamClient,284 mocks.resolver,285 mocks.zipStore,286 mocks.index,287 mocks.emitter,288 )289 err = dl.Download(serialModule)290 require.EqualError(t, err, "put zip failure")291}292func Test_Download_err_Put(t *testing.T) {293 mocks := newMocks()294 defer mocks.assertions(t)295 serialModule := coordinates.SerialModule{296 Module: coordinates.Module{297 Source: "github.com/pkg/errors",298 Version: "v1.2.3",299 },300 SerialID: 16,301 }302 upstreamRequest := &upstream.Request{303 Transport: "https",304 Domain: "github.com",305 Namespace: []string{"pkg", "errors"},306 Version: "v1.2.3",307 }308 originalBlob := dummyZip(t)309 rewrittenBlob, err := zips.Rewrite(serialModule.Module, originalBlob)310 require.NoError(t, err)311 mocks.resolver.On("Resolve", serialModule.Module).Return(312 upstreamRequest, nil,313 ).Once()314 mocks.upstreamClient.On("Get", upstreamRequest).Return(315 originalBlob, nil,316 ).Once()317 mocks.emitter.On("GaugeMS",318 "download-mod-elapsed-ms", mock.AnythingOfType("time.Time"),319 ).Once()320 mocks.zipStore.On("PutZip",321 serialModule.Module,322 rewrittenBlob,323 ).Return(nil).Once()324 mocks.index.On("Put", store.ModuleAddition{325 Mod: serialModule.Module,326 UniqueID: 16,327 ModFile: "module github.com/pkg/errors\n",328 }).Return(errors.New("put failure")).Once()329 dl := New(330 mocks.upstreamClient,331 mocks.resolver,332 mocks.zipStore,333 mocks.index,334 mocks.emitter,335 )336 err = dl.Download(serialModule)337 require.EqualError(t, err, "put failure")338}339*/...
NewMockS
Using AI Code Generation
1func (s *source) NewMockS() *mockS {2 return &mockS{source: s}3}4func (s *source) NewMockS() *mockS {5 return &mockS{source: s}6}7func (s *source) NewMockS() *mockS {8 return &mockS{source: s}9}10func (s *source) NewMockS() *mockS {11 return &mockS{source: s}12}13func (s *source) NewMockS() *mockS {14 return &mockS{source: s}15}16func (s *source) NewMockS() *mockS {17 return &mockS{source: s}18}19func (s *source) NewMockS() *mockS {20 return &mockS{source: s}21}22func (s *source) NewMockS() *mockS {23 return &mockS{source: s}24}25func (s *source) NewMockS() *mockS {26 return &mockS{source: s}27}28func (s *source) NewMockS() *mockS {29 return &mockS{source: s}30}31func (s *source) NewMockS() *mockS {32 return &mockS{source: s}33}34func (s *source) NewMockS() *mockS {35 return &mockS{source: s}36}
NewMockS
Using AI Code Generation
1func main() {2 m := NewMockS()3 fmt.Println(m.Foo())4}5func main() {6 m := NewMockS()7 fmt.Println(m.Foo())8}9func main() {10 m := NewMockS()11 fmt.Println(m.Foo())12}13func main() {14 m := NewMockS()15 fmt.Println(m.Foo())16}17func main() {18 m := NewMockS()19 fmt.Println(m.Foo())20}21func main() {22 m := NewMockS()23 fmt.Println(m.Foo())24}25func main() {26 m := NewMockS()27 fmt.Println(m.Foo())28}29func main() {30 m := NewMockS()31 fmt.Println(m.Foo())32}33func main() {34 m := NewMockS()35 fmt.Println(m.Foo())36}37func main() {38 m := NewMockS()39 fmt.Println(m.Foo())40}41func main() {42 m := NewMockS()43 fmt.Println(m.Foo())44}45func main() {46 m := NewMockS()47 fmt.Println(m.Foo())48}49func main() {50 m := NewMockS()51 fmt.Println(m.Foo())52}53func main() {54 m := NewMockS()55 fmt.Println(m.Foo())56}57func main() {58 m := NewMockS()59 fmt.Println(m.Foo())60}61func main() {62 m := NewMockS()63 fmt.Println(m.Foo())64}65func main() {66 m := NewMockS()67 fmt.Println(m.Foo())68}69func main() {70 m := NewMockS()71 fmt.Println(m.Foo())72}73func main() {74 m := NewMockS()75 fmt.Println(m.Foo())76}77func main() {
NewMockS
Using AI Code Generation
1func main() { 2 mockS := NewMockS()3 mockS.On("Read", 1).Return("1")4 mockS.On("Read", 2).Return("2")5 mockS.AssertExpectations()6}7func main() { 8 mockS := NewMockS()9 mockS.On("Read", 1).Return("1")10 mockS.On("Read", 2).Return("2")11 mockS.AssertExpectations()12}13func main() { 14 mockS := NewMockS()15 mockS.On("Read", 1).Return("1")16 mockS.On("Read", 2).Return("2")17 mockS.AssertExpectations()18}19func main() { 20 mockS := NewMockS()21 mockS.On("Read", 1).Return("1")22 mockS.On("Read", 2).Return("2")23 mockS.AssertExpectations()24}25func main() { 26 mockS := NewMockS()27 mockS.On("Read", 1).Return("1")28 mockS.On("Read", 2).Return("2")
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!