From 004c9432fabd1e93932c66097edc3b44abdc99e1 Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Wed, 22 Jan 2025 14:38:06 +0000 Subject: [PATCH] use stub instead of mock for test objects --- pkg/skaffold/docker/build_args_test.go | 4 +-- pkg/skaffold/docker/dockertest.go | 42 ++++++++++++------------- pkg/skaffold/graph/dependencies_test.go | 6 ++-- pkg/skaffold/tag/input_digest.go | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pkg/skaffold/docker/build_args_test.go b/pkg/skaffold/docker/build_args_test.go index bad76137011..a6b839b30d0 100644 --- a/pkg/skaffold/docker/build_args_test.go +++ b/pkg/skaffold/docker/build_args_test.go @@ -226,13 +226,13 @@ func TestCreateBuildArgsFromArtifacts(t *testing.T) { }{ { description: "can resolve artifacts", - r: NewMockArtifactResolver(map[string]string{"img1": "tag1", "img2": "tag2", "img3": "tag3", "img4": "tag4"}), + r: NewStubArtifactResolver(map[string]string{"img1": "tag1", "img2": "tag2", "img3": "tag3", "img4": "tag4"}), deps: []*latest.ArtifactDependency{{ImageName: "img3", Alias: "alias3"}, {ImageName: "img4", Alias: "alias4"}}, args: map[string]*string{"alias3": util.Ptr("tag3"), "alias4": util.Ptr("tag4")}, }, { description: "cannot resolve artifacts", - r: NewMockArtifactResolver(map[string]string{}), + r: NewStubArtifactResolver(map[string]string{}), args: map[string]*string{"alias3": nil, "alias4": nil}, deps: []*latest.ArtifactDependency{{ImageName: "img3", Alias: "alias3"}, {ImageName: "img4", Alias: "alias4"}}, }, diff --git a/pkg/skaffold/docker/dockertest.go b/pkg/skaffold/docker/dockertest.go index 32193c66d6e..833c51b713b 100644 --- a/pkg/skaffold/docker/dockertest.go +++ b/pkg/skaffold/docker/dockertest.go @@ -26,70 +26,70 @@ import ( ) // MockArtifactResolver mocks docker.ArtifactResolver interface. -type mockArtifactResolver struct { +type stubArtifactResolver struct { m map[string]string } -// NewMockArtifactResolver returns a mock ArtifactResolver for testing. -func NewMockArtifactResolver(m map[string]string) *mockArtifactResolver { - return &mockArtifactResolver{m} +// NewStubArtifactResolver returns a mock ArtifactResolver for testing. +func NewStubArtifactResolver(m map[string]string) *stubArtifactResolver { + return &stubArtifactResolver{m} } -func (r mockArtifactResolver) GetImageTag(imageName string) (string, bool) { +func (r stubArtifactResolver) GetImageTag(imageName string) (string, bool) { val, found := r.m[imageName] return val, found } -// simpleMockArtifactResolver is an implementation of docker.ArtifactResolver +// simpleStubArtifactResolver is an implementation of docker.ArtifactResolver // that returns the same value for any key -type simpleMockArtifactResolver struct{} +type simpleStubArtifactResolver struct{} // GetImageTag is an implementation of docker.ArtifactResolver that // always returns the same tag. -func (s *simpleMockArtifactResolver) GetImageTag(_ string) (string, bool) { +func (s *simpleStubArtifactResolver) GetImageTag(_ string) (string, bool) { return "image:latest", true } -func NewSimpleMockArtifactResolver() ArtifactResolver { - return &simpleMockArtifactResolver{} +func NewSimpleStubArtifactResolver() ArtifactResolver { + return &simpleStubArtifactResolver{} } -// MockConfig is a mock implementation of the Config interface. -type MockConfig struct { +// configStub is a mock implementation of the Config interface. +type configStub struct { runMode config.RunMode prune bool } -func (m MockConfig) GetKubeContext() string { +func (m configStub) GetKubeContext() string { return "" } -func (m MockConfig) GlobalConfig() string { +func (m configStub) GlobalConfig() string { return "" } -func (m MockConfig) MinikubeProfile() string { +func (m configStub) MinikubeProfile() string { return "" } -func (m MockConfig) GetInsecureRegistries() map[string]bool { +func (m configStub) GetInsecureRegistries() map[string]bool { return map[string]bool{} } -func (m MockConfig) Mode() config.RunMode { +func (m configStub) Mode() config.RunMode { return m.runMode } -func (m MockConfig) Prune() bool { +func (m configStub) Prune() bool { return m.prune } -func (m MockConfig) ContainerDebugging() bool { +func (m configStub) ContainerDebugging() bool { return false } -func NewMockConfig(mode config.RunMode, prune bool) Config { - return &MockConfig{runMode: mode, prune: prune} +func NewConfigStub(mode config.RunMode, prune bool) Config { + return &configStub{runMode: mode, prune: prune} } type fakeImageFetcher struct{} diff --git a/pkg/skaffold/graph/dependencies_test.go b/pkg/skaffold/graph/dependencies_test.go index 603876c764a..4e7d5c98a8f 100644 --- a/pkg/skaffold/graph/dependencies_test.go +++ b/pkg/skaffold/graph/dependencies_test.go @@ -49,7 +49,7 @@ func TestSourceDependenciesCache(t *testing.T) { return deps[a.ImageName], nil }) - r := NewSourceDependenciesCache(nil, docker.NewSimpleMockArtifactResolver(), g) + r := NewSourceDependenciesCache(nil, docker.NewSimpleStubArtifactResolver(), g) d, err := r.TransitiveArtifactDependencies(context.Background(), g["img1"]) t.CheckNoError(err) expectedDeps := []string{"file11", "file12", "file21", "file22", "file31", "file32", "file41", "file42", "file41", "file42"} @@ -108,7 +108,7 @@ func TestSourceDependenciesForArtifact(t *testing.T) { "IMAGE_NAME": "{{.IMAGE_NAME}}", "IMAGE_TAG": "{{.IMAGE_TAG}}", }, - dockerConfig: docker.NewMockConfig(config.RunModes.Build, false), + dockerConfig: docker.NewConfigStub(config.RunModes.Build, false), dockerFileContents: `ARG IMAGE_REPO ARG IMAGE_NAME ARG IMAGE_TAG @@ -129,7 +129,7 @@ COPY $IMAGE_TAG.go . t.Override(&docker.RetrieveImage, docker.NewFakeImageFetcher()) - d := docker.NewSimpleMockArtifactResolver() + d := docker.NewSimpleStubArtifactResolver() tmpDir.Write("Dockerfile", test.dockerFileContents) if test.dockerBuildArgs != nil { args := map[string]*string{} diff --git a/pkg/skaffold/tag/input_digest.go b/pkg/skaffold/tag/input_digest.go index 4273640dd4d..8223b761c9e 100644 --- a/pkg/skaffold/tag/input_digest.go +++ b/pkg/skaffold/tag/input_digest.go @@ -40,7 +40,7 @@ type inputDigestTagger struct { } func NewInputDigestTagger(cfg docker.Config, ag graph.ArtifactGraph) (Tagger, error) { - return NewInputDigestTaggerWithSourceCache(cfg, graph.NewSourceDependenciesCache(cfg, docker.NewSimpleMockArtifactResolver(), ag)) + return NewInputDigestTaggerWithSourceCache(cfg, graph.NewSourceDependenciesCache(cfg, docker.NewSimpleStubArtifactResolver(), ag)) } func NewInputDigestTaggerWithSourceCache(cfg docker.Config, cache graph.SourceDependenciesCache) (Tagger, error) {