Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/registry-facade-api/go/imagespec_test.go
2500 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
package api_test
6
7
import (
8
"testing"
9
10
"google.golang.org/protobuf/proto"
11
12
"github.com/gitpod-io/gitpod/registry-facade/api"
13
)
14
15
func TestBase64BackAndForth(t *testing.T) {
16
tests := []struct {
17
Desc string
18
Input *api.ImageSpec
19
}{
20
{"nil spec", nil},
21
{"base image only", &api.ImageSpec{BaseRef: "alpine:latest"}},
22
{"theia version only", &api.ImageSpec{IdeRef: "master.abc"}},
23
{"base image and theia", &api.ImageSpec{BaseRef: "alpine:latest", IdeRef: "master.2000"}},
24
{"content layer", &api.ImageSpec{
25
BaseRef: "something:latest",
26
ContentLayer: []*api.ContentLayer{
27
{
28
Spec: &api.ContentLayer_Remote{
29
Remote: &api.RemoteContentLayer{
30
DiffId: "sha256:abc",
31
Digest: "sha256:def",
32
Url: "https://soomewhere.over/the/rainbow",
33
},
34
},
35
},
36
},
37
}},
38
}
39
40
for _, test := range tests {
41
t.Run(test.Desc, func(t *testing.T) {
42
enc, err := test.Input.ToBase64()
43
if err != nil {
44
t.Errorf("unexpected error: %v", err)
45
return
46
}
47
48
spec, err := api.ImageSpecFromBase64(enc)
49
if err != nil {
50
t.Errorf("unexpected error: %v", err)
51
return
52
}
53
54
if !proto.Equal(spec, test.Input) {
55
t.Errorf("unexpected spec: expected \"%+q\", got \"%+q\"", test.Input, spec)
56
}
57
})
58
}
59
}
60
61