...
1
15
16 package content_test
17
18 import (
19 "context"
20 "io/ioutil"
21 "os"
22 "testing"
23
24 digest "github.com/opencontainers/go-digest"
25 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
26
27 "oras.land/oras-go/pkg/content"
28 )
29
30 func TestFileStoreNoName(t *testing.T) {
31 testContent := []byte("Hello World!")
32 descriptor := ocispec.Descriptor{
33 MediaType: ocispec.MediaTypeImageConfig,
34 Digest: digest.FromBytes(testContent),
35 Size: int64(len(testContent)),
36
37 }
38
39 tests := []struct {
40 opts []content.WriterOpt
41 err error
42 }{
43 {nil, nil},
44 {[]content.WriterOpt{content.WithErrorOnNoName()}, content.ErrNoName},
45 }
46 for _, tt := range tests {
47 rootPath, err := ioutil.TempDir("", "oras_filestore_test")
48 if err != nil {
49 t.Fatalf("error creating tempdir: %v", err)
50 }
51 defer os.RemoveAll(rootPath)
52 fileStore := content.NewFile(rootPath, tt.opts...)
53 ctx := context.Background()
54 pusher, _ := fileStore.Pusher(ctx, "")
55 if _, err := pusher.Push(ctx, descriptor); err != tt.err {
56 t.Errorf("mismatched error, actual '%v', expected '%v'", err, tt.err)
57 }
58
59 }
60 }
61
View as plain text