knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/test/upgrade/testing_types_test.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 upgrade_test 18 19 import ( 20 "bytes" 21 "sync" 22 23 "knative.dev/pkg/test/upgrade" 24 ) 25 26 type failurePoint struct { 27 step int 28 element int 29 } 30 31 type texts struct { 32 elms []string 33 } 34 35 type messageFormatter func(args ...interface{}) string 36 37 type step struct { 38 messages 39 ops operations 40 updateSuite func(ops operations, s *upgrade.Suite) 41 } 42 43 type operations struct { 44 ops []*operation 45 } 46 47 type operation struct { 48 op upgrade.Operation 49 bg upgrade.BackgroundOperation 50 } 51 52 type formats struct { 53 skipped string 54 starting string 55 element string 56 } 57 58 type messages struct { 59 starting messageFormatter 60 element messageFormatter 61 skipped messageFormatter 62 } 63 64 type messageFormatterRepository struct { 65 baseInstall messages 66 preUpgrade messages 67 startContinual messages 68 upgrade messages 69 postUpgrade messages 70 downgrade messages 71 postDowngrade messages 72 } 73 74 type component struct { 75 installs 76 tests 77 } 78 79 type installs struct { 80 stable upgrade.Operation 81 head upgrade.Operation 82 } 83 84 type tests struct { 85 preUpgrade upgrade.Operation 86 postUpgrade upgrade.Operation 87 continual upgrade.BackgroundOperation 88 postDowngrade upgrade.Operation 89 } 90 91 // threadSafeBuffer avoids race conditions on bytes.Buffer. 92 // See: https://stackoverflow.com/a/36226525/844449 93 type threadSafeBuffer struct { 94 bytes.Buffer 95 sync.Mutex 96 } 97 98 func (b *threadSafeBuffer) Read(p []byte) (n int, err error) { 99 b.Mutex.Lock() 100 defer b.Mutex.Unlock() 101 return b.Buffer.Read(p) 102 } 103 104 func (b *threadSafeBuffer) Write(p []byte) (n int, err error) { 105 b.Mutex.Lock() 106 defer b.Mutex.Unlock() 107 return b.Buffer.Write(p) 108 }