...

Source file src/github.com/google/go-containerregistry/pkg/registry/tls_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  	"testing"
    19  
    20  	"github.com/google/go-containerregistry/pkg/name"
    21  	"github.com/google/go-containerregistry/pkg/registry"
    22  	"github.com/google/go-containerregistry/pkg/v1/random"
    23  	"github.com/google/go-containerregistry/pkg/v1/remote"
    24  )
    25  
    26  func TestTLS(t *testing.T) {
    27  	s, err := registry.TLS("registry.example.com")
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	defer s.Close()
    32  
    33  	i, err := random.Image(1024, 1)
    34  	if err != nil {
    35  		t.Fatalf("Unable to make image: %v", err)
    36  	}
    37  	rd, err := i.Digest()
    38  	if err != nil {
    39  		t.Fatalf("Unable to get image digest: %v", err)
    40  	}
    41  
    42  	d, err := name.NewDigest("registry.example.com/foo@" + rd.String())
    43  	if err != nil {
    44  		t.Fatalf("Unable to parse digest: %v", err)
    45  	}
    46  	if err := remote.Write(d, i, remote.WithTransport(s.Client().Transport)); err != nil {
    47  		t.Fatalf("Unable to write image to remote: %s", err)
    48  	}
    49  }
    50  

View as plain text