...

Source file src/oras.land/oras-go/pkg/content/file_test.go

Documentation: oras.land/oras-go/pkg/content

     1  /*
     2  Copyright The ORAS Authors.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    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  		// do NOT add the AnnotationTitle here; it is the essence of the test
    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