go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cipkg/base/actions/cipd_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 actions
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"go.chromium.org/luci/cipkg/core"
    22  	"go.chromium.org/luci/cipkg/internal/testutils"
    23  	"go.chromium.org/luci/common/exec/execmock"
    24  
    25  	. "github.com/smartystreets/goconvey/convey"
    26  )
    27  
    28  func TestProcessCIPD(t *testing.T) {
    29  	Convey("Test action processor for cipd", t, func() {
    30  		ap := NewActionProcessor()
    31  		pm := testutils.NewMockPackageManage("")
    32  
    33  		cipd := &core.ActionCIPDExport{
    34  			EnsureFile: "infra/tools/luci/vpython/linux-amd64 git_revision:98782288dfc349541691a2a5dfc0e44327f22731",
    35  		}
    36  
    37  		pkg, err := ap.Process("", pm, &core.Action{
    38  			Name: "url",
    39  			Spec: &core.Action_Cipd{Cipd: cipd},
    40  		})
    41  		So(err, ShouldBeNil)
    42  
    43  		checkReexecArg(pkg.Derivation.Args, cipd)
    44  	})
    45  }
    46  
    47  func TestExecuteCIPD(t *testing.T) {
    48  	Convey("Test execute action cipd", t, func() {
    49  		ctx := execmock.Init(context.Background())
    50  		uses := execmock.Simple.Mock(ctx, execmock.SimpleInput{})
    51  		out := t.TempDir()
    52  
    53  		Convey("Test cipd export", func() {
    54  			a := &core.ActionCIPDExport{
    55  				EnsureFile: "",
    56  			}
    57  
    58  			err := ActionCIPDExportExecutor(ctx, a, out)
    59  			So(err, ShouldBeNil)
    60  
    61  			{
    62  				usage := uses.Snapshot()
    63  				So(usage, ShouldHaveLength, 1)
    64  				So(usage[0].Args[1:], ShouldEqual, []string{"export", "--root", out, "--ensure-file", "-"})
    65  			}
    66  		})
    67  	})
    68  }
    69  
    70  func TestReexecCIPD(t *testing.T) {
    71  	Convey("Test re-execute action processor for cipd", t, func() {
    72  		ctx := execmock.Init(context.Background())
    73  		uses := execmock.Simple.Mock(ctx, execmock.SimpleInput{})
    74  		ap := NewActionProcessor()
    75  		pm := testutils.NewMockPackageManage("")
    76  		out := t.TempDir()
    77  
    78  		pkg, err := ap.Process("", pm, &core.Action{
    79  			Name: "url",
    80  			Spec: &core.Action_Cipd{Cipd: &core.ActionCIPDExport{
    81  				EnsureFile: "",
    82  			}},
    83  		})
    84  		So(err, ShouldBeNil)
    85  
    86  		runWithDrv(ctx, pkg.Derivation, out)
    87  
    88  		{
    89  			usage := uses.Snapshot()
    90  			So(usage, ShouldHaveLength, 1)
    91  			So(usage[0].Args[1:], ShouldEqual, []string{"export", "--root", out, "--ensure-file", "-"})
    92  		}
    93  	})
    94  }