-
Notifications
You must be signed in to change notification settings - Fork 3
/
contentstore.go
76 lines (61 loc) · 2.15 KB
/
contentstore.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
package mocks
import (
"bytes"
"context"
"fmt"
"github.com/containerd/containerd/content"
"github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
)
// MockContentStore is a mock implementation of containerd's content store.
type MockContentStore struct {
Data map[string]string
}
var _ content.Store = &MockContentStore{}
// Info returns the content.Info for the given digest, if it exists in the mocked data keyed by digest.
func (m *MockContentStore) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
if d, ok := m.Data[dgst.String()]; ok {
return content.Info{
Digest: dgst,
Size: int64(len(d)),
}, nil
}
return content.Info{}, fmt.Errorf("digest not found: %s", dgst.String())
}
func (*MockContentStore) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
panic("not implemented")
}
func (*MockContentStore) Delete(ctx context.Context, dgst digest.Digest) error {
panic("not implemented")
}
// ReaderAt returns a content.ReaderAt for the given descriptor, if it exists in the mocked data keyed by digest.
func (m *MockContentStore) ReaderAt(ctx context.Context, desc v1.Descriptor) (content.ReaderAt, error) {
s, ok := m.Data[desc.Digest.String()]
if !ok {
return nil, fmt.Errorf("digest not found: %s", desc.Digest.String())
}
return &readerAt{*bytes.NewReader([]byte(s))}, nil
}
func (*MockContentStore) Status(ctx context.Context, ref string) (content.Status, error) {
panic("not implemented")
}
func (*MockContentStore) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
panic("not implemented")
}
func (*MockContentStore) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) {
panic("not implemented")
}
func (*MockContentStore) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) {
panic("not implemented")
}
func (*MockContentStore) Abort(ctx context.Context, ref string) error {
panic("not implemented")
}
type readerAt struct {
bytes.Reader
}
func (r *readerAt) Close() error {
return nil
}