...

Source file src/github.com/google/go-containerregistry/pkg/v1/manifest_test.go

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

     1  // Copyright 2018 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 v1
    16  
    17  import (
    18  	"strings"
    19  	"testing"
    20  
    21  	"github.com/google/go-cmp/cmp"
    22  )
    23  
    24  func TestGoodManifestSimple(t *testing.T) {
    25  	got, err := ParseManifest(strings.NewReader(`{}`))
    26  	if err != nil {
    27  		t.Errorf("Unexpected error parsing manifest: %v", err)
    28  	}
    29  
    30  	want := Manifest{}
    31  	if diff := cmp.Diff(want, *got); diff != "" {
    32  		t.Errorf("ParseManifest({}); (-want +got) %s", diff)
    33  	}
    34  }
    35  
    36  func TestGoodManifestWithHash(t *testing.T) {
    37  	good, err := ParseManifest(strings.NewReader(`{
    38    "config": {
    39      "digest": "sha256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
    40    }
    41  }`))
    42  	if err != nil {
    43  		t.Errorf("Unexpected error parsing manifest: %v", err)
    44  	}
    45  
    46  	if got, want := good.Config.Digest.Algorithm, "sha256"; got != want {
    47  		t.Errorf("ParseManifest().Config.Digest.Algorithm; got %v, want %v", got, want)
    48  	}
    49  }
    50  
    51  func TestManifestWithBadHash(t *testing.T) {
    52  	bad, err := ParseManifest(strings.NewReader(`{
    53    "config": {
    54      "digest": "sha256:deadbeed"
    55    }
    56  }`))
    57  	if err == nil {
    58  		t.Errorf("Expected error parsing manifest, but got: %v", bad)
    59  	}
    60  }
    61  
    62  func TestParseIndexManifest(t *testing.T) {
    63  	got, err := ParseIndexManifest(strings.NewReader(`{}`))
    64  	if err != nil {
    65  		t.Errorf("Unexpected error parsing manifest: %v", err)
    66  	}
    67  
    68  	want := IndexManifest{}
    69  	if diff := cmp.Diff(want, *got); diff != "" {
    70  		t.Errorf("ParseIndexManifest({}); (-want +got) %s", diff)
    71  	}
    72  
    73  	if got, err := ParseIndexManifest(strings.NewReader("{")); err == nil {
    74  		t.Errorf("expected error, got: %v", got)
    75  	}
    76  }
    77  

View as plain text