go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/vpython/wheels/wheels_test.go (about)

     1  // Copyright 2023 The LUCI Authors.
     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 wheels
    16  
    17  import (
    18  	"testing"
    19  
    20  	"go.chromium.org/luci/cipd/client/cipd/ensure"
    21  
    22  	"go.chromium.org/luci/vpython/api/vpython"
    23  
    24  	. "github.com/smartystreets/goconvey/convey"
    25  )
    26  
    27  func TestGeneratingEnsureFile(t *testing.T) {
    28  	Convey("Test generate ensure file", t, func() {
    29  		ef, err := ensureFileFromVPythonSpec(&vpython.Spec{
    30  			Wheel: []*vpython.Spec_Package{
    31  				{Name: "pkg1", Version: "version1"},
    32  				{Name: "pkg2", Version: "version2"},
    33  			},
    34  		}, nil)
    35  		So(err, ShouldBeNil)
    36  		So(ef.PackagesBySubdir["wheels"], ShouldResemble, ensure.PackageSlice{
    37  			{PackageTemplate: "pkg1", UnresolvedVersion: "version1"},
    38  			{PackageTemplate: "pkg2", UnresolvedVersion: "version2"},
    39  		})
    40  
    41  	})
    42  	Convey("Test duplicated wheels", t, func() {
    43  		Convey("Same version", func() {
    44  			ef, err := ensureFileFromVPythonSpec(&vpython.Spec{
    45  				Wheel: []*vpython.Spec_Package{
    46  					{Name: "pkg1", Version: "version1"},
    47  					{Name: "pkg1", Version: "version1"},
    48  				},
    49  			}, nil)
    50  			So(err, ShouldBeNil)
    51  			So(ef.PackagesBySubdir["wheels"], ShouldResemble, ensure.PackageSlice{
    52  				{PackageTemplate: "pkg1", UnresolvedVersion: "version1"},
    53  			})
    54  		})
    55  		Convey("Different version", func() {
    56  			_, err := ensureFileFromVPythonSpec(&vpython.Spec{
    57  				Wheel: []*vpython.Spec_Package{
    58  					{Name: "pkg1", Version: "version1"},
    59  					{Name: "pkg1", Version: "version2"},
    60  				},
    61  			}, nil)
    62  			So(err, ShouldNotBeNil)
    63  			So(err.Error(), ShouldStartWith, "multiple versions for package")
    64  		})
    65  	})
    66  	Convey("Test match tag", t, func() {
    67  		Convey("match", func() {
    68  			ef, err := ensureFileFromVPythonSpec(&vpython.Spec{
    69  				Wheel: []*vpython.Spec_Package{
    70  					{Name: "pkg1", Version: "version1", MatchTag: []*vpython.PEP425Tag{{Platform: "manylinux1_x86_64"}}},
    71  					{Name: "pkg2", Version: "version2"},
    72  				},
    73  			}, []*vpython.PEP425Tag{{Platform: "manylinux1_x86_64"}})
    74  			So(err, ShouldBeNil)
    75  			So(ef.PackagesBySubdir["wheels"], ShouldResemble, ensure.PackageSlice{
    76  				{PackageTemplate: "pkg1", UnresolvedVersion: "version1"},
    77  				{PackageTemplate: "pkg2", UnresolvedVersion: "version2"},
    78  			})
    79  		})
    80  		Convey("mismatch", func() {
    81  			ef, err := ensureFileFromVPythonSpec(&vpython.Spec{
    82  				Wheel: []*vpython.Spec_Package{
    83  					{Name: "pkg1", Version: "version1", MatchTag: []*vpython.PEP425Tag{{Platform: "manylinux1_x86_64"}}},
    84  					{Name: "pkg2", Version: "version2"},
    85  				},
    86  			}, []*vpython.PEP425Tag{{Platform: "manylinux1_aarch64"}})
    87  			So(err, ShouldBeNil)
    88  			So(ef.PackagesBySubdir["wheels"], ShouldResemble, ensure.PackageSlice{
    89  				{PackageTemplate: "pkg2", UnresolvedVersion: "version2"},
    90  			})
    91  		})
    92  	})
    93  }