knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/test/upgrade/shell/types.go (about) 1 /* 2 Copyright 2020 The Knative Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package shell 18 19 import ( 20 "io" 21 ) 22 23 // Option overrides configuration options in ExecutorConfig. 24 type Option func(*ExecutorConfig) 25 26 // ProjectLocation represents a project location on a file system. 27 type ProjectLocation interface { 28 RootPath() string 29 } 30 31 // Script represents a script to be executed. 32 type Script struct { 33 Label string 34 ScriptPath string 35 } 36 37 // Function represents a function, whom will be sourced from Script file, 38 // and executed. 39 type Function struct { 40 Script 41 FunctionName string 42 } 43 44 // ExecutorConfig holds executor configuration options. 45 type ExecutorConfig struct { 46 ProjectLocation 47 Streams 48 Labels 49 Environ []string 50 } 51 52 // TestingT is used by testingWriter and allows passing testing.T. 53 type TestingT interface { 54 Logf(format string, args ...any) 55 } 56 57 // testingWriter implements io.Writer and writes to given testing.T log. 58 type testingWriter struct { 59 t TestingT 60 } 61 62 // StreamType represets either output or error stream. 63 type StreamType int 64 65 const ( 66 // StreamTypeOut represents process output stream. 67 StreamTypeOut StreamType = iota 68 // StreamTypeErr represents process error stream. 69 StreamTypeErr 70 ) 71 72 // PrefixFunc is used to build a prefix that will be added to each line of the 73 // script/function output or error stream. 74 type PrefixFunc func(st StreamType, label string, config ExecutorConfig) string 75 76 // Labels holds a labels to be used to prefix Out and Err streams of executed 77 // shells scripts/functions. 78 type Labels struct { 79 LabelOut string 80 LabelErr string 81 SkipDate bool 82 DateFormat string 83 PrefixFunc 84 } 85 86 // Streams holds a streams of a shell scripts/functions. 87 type Streams struct { 88 Out io.Writer 89 Err io.Writer 90 } 91 92 // Executor represents a executor that can execute shell scripts and call 93 // functions directly. 94 type Executor interface { 95 RunScript(script Script, args ...string) error 96 RunFunction(fn Function, args ...string) error 97 }