...

Source file src/github.com/google/go-containerregistry/pkg/registry/compatibility_test.go

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

     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 registry_test
    16  
    17  import (
    18  	"bytes"
    19  	"net/http/httptest"
    20  	"strings"
    21  	"testing"
    22  
    23  	"github.com/google/go-containerregistry/pkg/name"
    24  	"github.com/google/go-containerregistry/pkg/registry"
    25  	"github.com/google/go-containerregistry/pkg/v1/random"
    26  	"github.com/google/go-containerregistry/pkg/v1/remote"
    27  	"github.com/google/go-containerregistry/pkg/v1/tarball"
    28  )
    29  
    30  func TestPushAndPullContainer(t *testing.T) {
    31  	s := httptest.NewServer(registry.New())
    32  	defer s.Close()
    33  
    34  	r := strings.TrimPrefix(s.URL, "http://") + "/foo:latest"
    35  	d, err := name.NewTag(r)
    36  	if err != nil {
    37  		t.Fatalf("Unable to create tag: %v", err)
    38  	}
    39  
    40  	i, err := random.Image(1024, 1)
    41  	if err != nil {
    42  		t.Fatalf("Unable to make random image: %v", err)
    43  	}
    44  
    45  	if err := remote.Write(d, i); err != nil {
    46  		t.Fatalf("Error writing image: %v", err)
    47  	}
    48  
    49  	ref, err := name.ParseReference(r)
    50  	if err != nil {
    51  		t.Fatalf("Error parsing tag: %v", err)
    52  	}
    53  
    54  	ri, err := remote.Image(ref)
    55  	if err != nil {
    56  		t.Fatalf("Error reading image: %v", err)
    57  	}
    58  
    59  	b := &bytes.Buffer{}
    60  	if err := tarball.Write(ref, ri, b); err != nil {
    61  		t.Fatalf("Error writing image to tarball: %v", err)
    62  	}
    63  }
    64  

View as plain text