...

Source file src/github.com/google/go-containerregistry/pkg/crane/append_test.go

Documentation: github.com/google/go-containerregistry/pkg/crane

     1  // Copyright 2022 Google LLC All Rights Reserved.
     2  //
     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  package crane_test
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/google/go-containerregistry/pkg/crane"
    21  	"github.com/google/go-containerregistry/pkg/v1/empty"
    22  	"github.com/google/go-containerregistry/pkg/v1/mutate"
    23  	"github.com/google/go-containerregistry/pkg/v1/types"
    24  )
    25  
    26  func TestAppendWithOCIBaseImage(t *testing.T) {
    27  	base := mutate.MediaType(empty.Image, types.OCIManifestSchema1)
    28  	img, err := crane.Append(base, "testdata/content.tar")
    29  
    30  	if err != nil {
    31  		t.Fatalf("crane.Append(): %v", err)
    32  	}
    33  
    34  	layers, err := img.Layers()
    35  
    36  	if err != nil {
    37  		t.Fatalf("img.Layers(): %v", err)
    38  	}
    39  
    40  	mediaType, err := layers[0].MediaType()
    41  
    42  	if err != nil {
    43  		t.Fatalf("layers[0].MediaType(): %v", err)
    44  	}
    45  
    46  	if got, want := mediaType, types.OCILayer; got != want {
    47  		t.Errorf("MediaType(): want %q, got %q", want, got)
    48  	}
    49  }
    50  
    51  func TestAppendWithDockerBaseImage(t *testing.T) {
    52  	img, err := crane.Append(empty.Image, "testdata/content.tar")
    53  
    54  	if err != nil {
    55  		t.Fatalf("crane.Append(): %v", err)
    56  	}
    57  
    58  	layers, err := img.Layers()
    59  
    60  	if err != nil {
    61  		t.Fatalf("img.Layers(): %v", err)
    62  	}
    63  
    64  	mediaType, err := layers[0].MediaType()
    65  
    66  	if err != nil {
    67  		t.Fatalf("layers[0].MediaType(): %v", err)
    68  	}
    69  
    70  	if got, want := mediaType, types.DockerLayer; got != want {
    71  		t.Errorf("MediaType(): want %q, got %q", want, got)
    72  	}
    73  }
    74  

View as plain text