Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/registry-facade/pkg/registry/layersource_ext_test.go
2499 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
//go:generate mockgen -package mock github.com/gitpod-io/gitpod/registry-facade/pkg/registry LayerSource > pkg/registry/mock/layersource_mock.go
6
7
package registry_test
8
9
import (
10
"context"
11
"testing"
12
13
"github.com/golang/mock/gomock"
14
"github.com/opencontainers/go-digest"
15
16
"github.com/gitpod-io/gitpod/registry-facade/pkg/registry"
17
"github.com/gitpod-io/gitpod/registry-facade/pkg/registry/mock"
18
)
19
20
func TestRevisioingLayerSource(t *testing.T) {
21
tests := []struct {
22
Name string
23
Run func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource)
24
}{
25
{
26
Name: "hasBlob",
27
Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {
28
s0.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).MinTimes(2)
29
rev.HasBlob(context.Background(), nil, digest.FromString(""))
30
31
rev.Update(s1)
32
s1.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(true)
33
if !rev.HasBlob(context.Background(), nil, digest.FromString("")) {
34
t.Error("expected hasBlob == true")
35
}
36
37
s1.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(false)
38
rev.HasBlob(context.Background(), nil, digest.FromString(""))
39
},
40
},
41
{
42
Name: "getBlob active !hasBlob",
43
Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {
44
s0.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(false).MinTimes(1)
45
rev.GetBlob(context.Background(), nil, digest.FromString(""))
46
},
47
},
48
{
49
Name: "getBlob active hasBlob",
50
Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {
51
s0.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(true).MinTimes(1)
52
s0.EXPECT().GetBlob(gomock.Any(), gomock.Any(), gomock.Any()).MinTimes(1)
53
rev.GetBlob(context.Background(), nil, digest.FromString(""))
54
},
55
},
56
{
57
Name: "getBlob new active hasBlob",
58
Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {
59
s1.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(true).MinTimes(1)
60
s1.EXPECT().GetBlob(gomock.Any(), gomock.Any(), gomock.Any()).MinTimes(1)
61
62
rev.Update(s1)
63
rev.GetBlob(context.Background(), nil, digest.FromString(""))
64
},
65
},
66
{
67
Name: "getBlob new active !hasBlob",
68
Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {
69
s0.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(true).MinTimes(1)
70
s0.EXPECT().GetBlob(gomock.Any(), gomock.Any(), gomock.Any()).MinTimes(1)
71
s1.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(false).MinTimes(1)
72
73
rev.Update(s1)
74
rev.GetBlob(context.Background(), nil, digest.FromString(""))
75
},
76
},
77
{
78
Name: "active only",
79
Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {
80
s1.EXPECT().Envs(gomock.Any(), gomock.Any()).MinTimes(1)
81
s1.EXPECT().GetLayer(gomock.Any(), gomock.Any()).MinTimes(1)
82
83
rev.Update(s1)
84
rev.GetLayer(context.Background(), nil)
85
rev.Envs(context.Background(), nil)
86
},
87
},
88
}
89
90
for _, test := range tests {
91
t.Run(test.Name, func(t *testing.T) {
92
ctrl := gomock.NewController(t)
93
defer ctrl.Finish()
94
95
s0 := mock.NewMockLayerSource(ctrl)
96
s1 := mock.NewMockLayerSource(ctrl)
97
s2 := mock.NewMockLayerSource(ctrl)
98
rev := registry.NewRevisioningLayerSource(s0)
99
100
test.Run(rev, s0, s1, s2)
101
})
102
}
103
}
104
105