go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/exec/execmock/mock_start_error.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 execmock 16 17 import ( 18 "context" 19 20 "go.chromium.org/luci/common/exec/internal/execmockserver" 21 ) 22 23 type startErrorMocker struct { 24 f filter 25 } 26 27 func (e *startErrorMocker) Mock(ctx context.Context, errs ...error) *Uses[None] { 28 return addMockEntry[None](ctx, e.f, &execmockserver.InvocationInput{ 29 StartError: getOne(errs), 30 }) 31 } 32 33 func (e *startErrorMocker) WithArgs(argPattern ...string) Mocker[error, None] { 34 ret := *e 35 ret.f = e.f.withArgs(argPattern) 36 return &ret 37 } 38 39 func (e *startErrorMocker) WithEnv(varName, valuePattern string) Mocker[error, None] { 40 ret := *e 41 ret.f = e.f.withEnv(varName, valuePattern) 42 return &ret 43 } 44 45 func (e *startErrorMocker) WithLimit(limit uint64) Mocker[error, None] { 46 ret := *e 47 ret.f.limit = limit 48 return &ret 49 } 50 51 // StartError allows you to mock any execution with an error which will be 52 // returned from Start() (i.e. no process will actually run). 53 // 54 // This can be used to return exec.ErrNotFound from a given invocation, or any 55 // other error (e.g. bad executable file, or whatever you like). 56 var StartError Mocker[error, None] = &startErrorMocker{}