5
5
package utils
6
6
7
7
import (
8
+ "bytes"
9
+ "context"
8
10
"os"
9
11
"path/filepath"
10
12
"strconv"
@@ -20,6 +22,7 @@ import (
20
22
"k8s.io/client-go/tools/clientcmd"
21
23
22
24
buildClient "github.com/shipwright-io/build/pkg/client/build/clientset/versioned"
25
+ "github.com/shipwright-io/build/pkg/ctxlog"
23
26
"github.com/shipwright-io/build/test"
24
27
// from https://github.com/kubernetes/client-go/issues/345
25
28
)
@@ -35,22 +38,29 @@ type TestBuild struct {
35
38
// TODO: Adding specific field for polling here, interval and timeout
36
39
// but I think we need a small refactoring to make them global for all
37
40
// tests under /test dir
38
- Interval time.Duration
39
- TimeOut time.Duration
40
- KubeConfig * rest.Config
41
- Clientset * kubernetes.Clientset
42
- Namespace string
43
- StopBuildOperator chan struct {}
44
- BuildClientSet * buildClient.Clientset
45
- PipelineClientSet * tektonClient.Clientset
46
- Catalog test.Catalog
41
+ Interval time.Duration
42
+ TimeOut time.Duration
43
+ KubeConfig * rest.Config
44
+ Clientset * kubernetes.Clientset
45
+ Namespace string
46
+ StopBuildOperator chan struct {}
47
+ BuildClientSet * buildClient.Clientset
48
+ PipelineClientSet * tektonClient.Clientset
49
+ Catalog test.Catalog
50
+ Context context.Context
51
+ BuildOperatorLogBuffer * bytes.Buffer
47
52
}
48
53
49
54
// NewTestBuild returns an initialized instance of TestBuild
50
55
func NewTestBuild () (* TestBuild , error ) {
51
56
namespaceID := gomegaConfig .GinkgoConfig .ParallelNode * 200 + int (atomic .AddInt32 (& namespaceCounter , 1 ))
52
57
testNamespace := "test-build-" + strconv .Itoa (int (namespaceID ))
53
58
59
+ logBuffer := & bytes.Buffer {}
60
+ l := ctxlog .NewLoggerTo (logBuffer , testNamespace )
61
+
62
+ ctx := ctxlog .NewParentContext (l )
63
+
54
64
kubeConfig , restConfig , err := KubeConfig ()
55
65
if err != nil {
56
66
return nil , err
@@ -70,13 +80,15 @@ func NewTestBuild() (*TestBuild, error) {
70
80
71
81
return & TestBuild {
72
82
// TODO: interval and timeout can be configured via ENV vars
73
- Interval : time .Second * 3 ,
74
- TimeOut : time .Second * 180 ,
75
- KubeConfig : restConfig ,
76
- Clientset : kubeConfig ,
77
- Namespace : testNamespace ,
78
- BuildClientSet : buildClientSet ,
79
- PipelineClientSet : pipelineClientSet ,
83
+ Interval : time .Second * 3 ,
84
+ TimeOut : time .Second * 180 ,
85
+ KubeConfig : restConfig ,
86
+ Clientset : kubeConfig ,
87
+ Namespace : testNamespace ,
88
+ BuildClientSet : buildClientSet ,
89
+ PipelineClientSet : pipelineClientSet ,
90
+ Context : ctx ,
91
+ BuildOperatorLogBuffer : logBuffer ,
80
92
}, nil
81
93
}
82
94
0 commit comments