Path: blob/main/components/registry-facade/pkg/registry/layersource_ext_test.go
2499 views
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34//go:generate mockgen -package mock github.com/gitpod-io/gitpod/registry-facade/pkg/registry LayerSource > pkg/registry/mock/layersource_mock.go56package registry_test78import (9"context"10"testing"1112"github.com/golang/mock/gomock"13"github.com/opencontainers/go-digest"1415"github.com/gitpod-io/gitpod/registry-facade/pkg/registry"16"github.com/gitpod-io/gitpod/registry-facade/pkg/registry/mock"17)1819func TestRevisioingLayerSource(t *testing.T) {20tests := []struct {21Name string22Run func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource)23}{24{25Name: "hasBlob",26Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {27s0.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).MinTimes(2)28rev.HasBlob(context.Background(), nil, digest.FromString(""))2930rev.Update(s1)31s1.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(true)32if !rev.HasBlob(context.Background(), nil, digest.FromString("")) {33t.Error("expected hasBlob == true")34}3536s1.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(false)37rev.HasBlob(context.Background(), nil, digest.FromString(""))38},39},40{41Name: "getBlob active !hasBlob",42Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {43s0.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(false).MinTimes(1)44rev.GetBlob(context.Background(), nil, digest.FromString(""))45},46},47{48Name: "getBlob active hasBlob",49Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {50s0.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(true).MinTimes(1)51s0.EXPECT().GetBlob(gomock.Any(), gomock.Any(), gomock.Any()).MinTimes(1)52rev.GetBlob(context.Background(), nil, digest.FromString(""))53},54},55{56Name: "getBlob new active hasBlob",57Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {58s1.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(true).MinTimes(1)59s1.EXPECT().GetBlob(gomock.Any(), gomock.Any(), gomock.Any()).MinTimes(1)6061rev.Update(s1)62rev.GetBlob(context.Background(), nil, digest.FromString(""))63},64},65{66Name: "getBlob new active !hasBlob",67Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {68s0.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(true).MinTimes(1)69s0.EXPECT().GetBlob(gomock.Any(), gomock.Any(), gomock.Any()).MinTimes(1)70s1.EXPECT().HasBlob(gomock.Any(), gomock.Any(), gomock.Any()).Return(false).MinTimes(1)7172rev.Update(s1)73rev.GetBlob(context.Background(), nil, digest.FromString(""))74},75},76{77Name: "active only",78Run: func(rev *registry.RevisioningLayerSource, s0, s1, s2 *mock.MockLayerSource) {79s1.EXPECT().Envs(gomock.Any(), gomock.Any()).MinTimes(1)80s1.EXPECT().GetLayer(gomock.Any(), gomock.Any()).MinTimes(1)8182rev.Update(s1)83rev.GetLayer(context.Background(), nil)84rev.Envs(context.Background(), nil)85},86},87}8889for _, test := range tests {90t.Run(test.Name, func(t *testing.T) {91ctrl := gomock.NewController(t)92defer ctrl.Finish()9394s0 := mock.NewMockLayerSource(ctrl)95s1 := mock.NewMockLayerSource(ctrl)96s2 := mock.NewMockLayerSource(ctrl)97rev := registry.NewRevisioningLayerSource(s0)9899test.Run(rev, s0, s1, s2)100})101}102}103104105