github.com/google/osv-scalibr@v0.4.1/binary/proto/container_image_metadata_test.go (about)

     1  // Copyright 2025 Google LLC
     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 proto_test
    16  
    17  import (
    18  	"github.com/google/osv-scalibr/extractor"
    19  	"github.com/opencontainers/go-digest"
    20  
    21  	pb "github.com/google/osv-scalibr/binary/proto/scan_result_go_proto"
    22  )
    23  
    24  var d1 = digest.FromString("d1")
    25  var d2 = digest.FromString("d2")
    26  
    27  var cimProtoForTest = &pb.ContainerImageMetadata{
    28  	Index: 0,
    29  	LayerMetadata: []*pb.LayerMetadata{
    30  		{Index: 0, DiffId: d1.String(), ChainId: d1.String(), Command: "cmd1", IsEmpty: false, BaseImageIndex: 1},
    31  		{Index: 1, DiffId: d2.String(), ChainId: d2.String(), Command: "cmd2", IsEmpty: true, BaseImageIndex: 0},
    32  	},
    33  	BaseImageChains: []*pb.BaseImageChain{
    34  		{},
    35  		{
    36  			ChainId: d1.String(),
    37  			BaseImages: []*pb.BaseImageDetails{
    38  				{Repository: "base-image", Registry: "ghcr.io", Plugin: "baseimage"},
    39  			},
    40  		},
    41  	},
    42  }
    43  
    44  var cimStructForTest = func() *extractor.ContainerImageMetadata {
    45  	c := &extractor.ContainerImageMetadata{
    46  		Index: 0,
    47  		LayerMetadata: []*extractor.LayerMetadata{
    48  			{Index: 0, DiffID: d1, ChainID: d1, Command: "cmd1", IsEmpty: false, BaseImageIndex: 1},
    49  			{Index: 1, DiffID: d2, ChainID: d2, Command: "cmd2", IsEmpty: true, BaseImageIndex: 0},
    50  		},
    51  		BaseImages: [][]*extractor.BaseImageDetails{
    52  			{},
    53  			{
    54  				{Repository: "base-image", Registry: "ghcr.io", Plugin: "baseimage", ChainID: d1},
    55  			},
    56  		},
    57  	}
    58  	for _, lm := range c.LayerMetadata {
    59  		lm.ParentContainer = c
    60  	}
    61  	return c
    62  }()
    63  
    64  var pkgWithLayerStruct = &extractor.Package{
    65  	Name:          "withlayer",
    66  	Version:       "1.0",
    67  	LayerMetadata: cimStructForTest.LayerMetadata[0],
    68  }
    69  
    70  var pkgWithLayerProto = &pb.Package{
    71  	Name:    "withlayer",
    72  	Version: "1.0",
    73  	ContainerImageMetadataIndexes: &pb.Package_ContainerImageMetadataIndexes{
    74  		LayerIndex:          0,
    75  		ContainerImageIndex: 0,
    76  	},
    77  }