github.com/opentofu/opentofu@v1.7.1/internal/tofu/ui_input_mock.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package tofu 7 8 import "context" 9 10 // MockUIInput is an implementation of UIInput that can be used for tests. 11 type MockUIInput struct { 12 InputCalled bool 13 InputOpts *InputOpts 14 InputReturnMap map[string]string 15 InputReturnString string 16 InputReturnError error 17 InputFn func(*InputOpts) (string, error) 18 } 19 20 func (i *MockUIInput) Input(ctx context.Context, opts *InputOpts) (string, error) { 21 i.InputCalled = true 22 i.InputOpts = opts 23 if i.InputFn != nil { 24 return i.InputFn(opts) 25 } 26 if i.InputReturnMap != nil { 27 return i.InputReturnMap[opts.Id], i.InputReturnError 28 } 29 return i.InputReturnString, i.InputReturnError 30 }