/
stubs_test.go
207 lines (159 loc) · 5.49 KB
/
stubs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package stage
import (
"context"
v1 "github.com/google/go-containerregistry/pkg/v1"
. "github.com/onsi/gomega"
"github.com/werf/werf/pkg/container_runtime"
"github.com/werf/werf/pkg/docker_registry"
"github.com/werf/werf/pkg/git_repo"
"github.com/werf/werf/pkg/giterminism_manager"
"github.com/werf/werf/pkg/image"
)
type LegacyImageStub struct {
container_runtime.LegacyImageInterface
_Container *LegacyContainerStub
_DockerfileImageBuilder *container_runtime.DockerfileImageBuilder
}
func NewLegacyImageStub() *LegacyImageStub {
return &LegacyImageStub{
_Container: NewLegacyContainerStub(),
}
}
func (img *LegacyImageStub) Container() container_runtime.LegacyContainer {
return img._Container
}
func (img *LegacyImageStub) DockerfileImageBuilder() *container_runtime.DockerfileImageBuilder {
if img._DockerfileImageBuilder == nil {
img._DockerfileImageBuilder = container_runtime.NewDockerfileImageBuilder(nil)
}
return img._DockerfileImageBuilder
}
type LegacyContainerStub struct {
container_runtime.LegacyContainer
_ServiceCommitChangeOptions *LegacyContainerOptionsStub
}
func NewLegacyContainerStub() *LegacyContainerStub {
return &LegacyContainerStub{
_ServiceCommitChangeOptions: NewLegacyContainerOptionsStub(),
}
}
func (c *LegacyContainerStub) ServiceCommitChangeOptions() container_runtime.LegacyContainerOptions {
return c._ServiceCommitChangeOptions
}
type LegacyContainerOptionsStub struct {
container_runtime.LegacyContainerOptions
Env map[string]string
}
func NewLegacyContainerOptionsStub() *LegacyContainerOptionsStub {
return &LegacyContainerOptionsStub{Env: make(map[string]string)}
}
func (opts *LegacyContainerOptionsStub) AddEnv(envs map[string]string) {
for k, v := range envs {
opts.Env[k] = v
}
}
type ConveyorStub struct {
Conveyor
giterminismManager *GiterminismManagerStub
lastStageImageNameByImageName map[string]string
lastStageImageIDByImageName map[string]string
}
func NewConveyorStub(giterminismManager *GiterminismManagerStub, lastStageImageNameByImageName, lastStageImageIDByImageName map[string]string) *ConveyorStub {
return &ConveyorStub{
giterminismManager: giterminismManager,
lastStageImageNameByImageName: lastStageImageNameByImageName,
lastStageImageIDByImageName: lastStageImageIDByImageName,
}
}
func NewConveyorStubForDependencies(giterminismManager *GiterminismManagerStub, dependencies []*TestDependency) *ConveyorStub {
lastStageImageNameByImageName := make(map[string]string)
lastStageImageIDByImageName := make(map[string]string)
for _, dep := range dependencies {
lastStageImageNameByImageName[dep.ImageName] = dep.GetDockerImageName()
lastStageImageIDByImageName[dep.ImageName] = dep.DockerImageID
}
return NewConveyorStub(giterminismManager, lastStageImageNameByImageName, lastStageImageIDByImageName)
}
func (c *ConveyorStub) GetImageNameForLastImageStage(imageName string) string {
return c.lastStageImageNameByImageName[imageName]
}
func (c *ConveyorStub) GetImageIDForLastImageStage(imageName string) string {
return c.lastStageImageIDByImageName[imageName]
}
func (c *ConveyorStub) GiterminismManager() giterminism_manager.Interface {
return c.giterminismManager
}
type GiterminismManagerStub struct {
giterminism_manager.Interface
localGitRepo git_repo.GitRepo
}
func NewGiterminismManagerStub(localGitRepo git_repo.GitRepo) *GiterminismManagerStub {
return &GiterminismManagerStub{
localGitRepo: localGitRepo,
}
}
func (manager *GiterminismManagerStub) RelativeToGitProjectDir() string {
return ""
}
func (manager *GiterminismManagerStub) LocalGitRepo() git_repo.GitRepo {
return manager.localGitRepo
}
func (manager *GiterminismManagerStub) Dev() bool {
return false
}
func (manager *GiterminismManagerStub) HeadCommit() string {
commit, err := manager.localGitRepo.HeadCommitHash(context.Background())
Expect(err).To(Succeed())
return commit
}
type LocalGitRepoStub struct {
git_repo.GitRepo
headCommitHash string
}
func NewLocalGitRepoStub(headCommitHash string) *LocalGitRepoStub {
return &LocalGitRepoStub{
headCommitHash: headCommitHash,
}
}
func (repo *LocalGitRepoStub) HeadCommitHash(ctx context.Context) (string, error) {
return repo.headCommitHash, nil
}
func (repo *LocalGitRepoStub) GetOrCreateArchive(ctx context.Context, opts git_repo.ArchiveOptions) (git_repo.Archive, error) {
return NewGitRepoArchiveStub(), nil
}
type GitRepoArchiveStub struct {
git_repo.Archive
}
func NewGitRepoArchiveStub() *GitRepoArchiveStub {
return &GitRepoArchiveStub{}
}
func (archive *GitRepoArchiveStub) GetFilePath() string {
return "no-such-file"
}
type ContainerRuntimeMock struct {
container_runtime.ContainerRuntime
_PulledImages map[string]bool
}
func NewContainerRuntimeMock() *ContainerRuntimeMock {
return &ContainerRuntimeMock{
_PulledImages: make(map[string]bool),
}
}
func (containerRuntime *ContainerRuntimeMock) GetImageInfo(ctx context.Context, ref string, opts container_runtime.GetImageInfoOpts) (*image.Info, error) {
return nil, nil
}
func (containerRuntime *ContainerRuntimeMock) Pull(ctx context.Context, ref string, opts container_runtime.PullOpts) error {
containerRuntime._PulledImages[ref] = true
return nil
}
type DockerRegistryStub struct {
docker_registry.DockerRegistryInterface
}
func NewDockerRegistryStub() *DockerRegistryStub {
return &DockerRegistryStub{}
}
func (dockerRegistry *DockerRegistryStub) GetRepoImageConfigFile(ctx context.Context, reference string) (*v1.ConfigFile, error) {
return &v1.ConfigFile{
Config: v1.Config{},
}, nil
}