github.com/uber/kraken@v0.1.4/utils/dockerutil/fixtures.go (about)

     1  // Copyright (c) 2016-2019 Uber Technologies, Inc.
     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  package dockerutil
    15  
    16  import (
    17  	"fmt"
    18  
    19  	"github.com/uber/kraken/core"
    20  )
    21  
    22  // ManifestFixture creates a manifest blob for testing purposes.
    23  func ManifestFixture(config core.Digest, layer1 core.Digest, layer2 core.Digest) (core.Digest, []byte) {
    24  	raw := []byte(fmt.Sprintf(`{
    25  	   "schemaVersion": 2,
    26  	   "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    27  	   "config": {
    28  		  "mediaType": "application/vnd.docker.container.image.v1+json",
    29  		  "size": 2940,
    30  		  "digest": "%s"
    31  	   },
    32  	   "layers": [
    33  		  {
    34  			 "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
    35  			 "size": 1902063,
    36  			 "digest": "%s"
    37  		  },
    38  		  {
    39  			 "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
    40  			 "size": 2345077,
    41  			 "digest": "%s"
    42  		  }
    43  	   ]
    44  	}`, config, layer1, layer2))
    45  
    46  	d, err := core.NewDigester().FromBytes(raw)
    47  	if err != nil {
    48  		panic(err)
    49  	}
    50  
    51  	return d, raw
    52  }