@@ -48,78 +48,90 @@ type E2EStorageIntegration struct {
48
48
HealthCheckEndpoint string
49
49
}
50
50
51
- // e2eInitialize starts the Jaeger-v2 collector with the provided config file,
52
- // it also initialize the SpanWriter and SpanReader below.
53
- // This function should be called before any of the tests start.
54
- func (s * E2EStorageIntegration ) e2eInitialize (t * testing.T , storage string ) {
55
- logger := zaptest .NewLogger (t , zaptest .WrapOptions (zap .AddCaller ()))
56
- if s .BinaryName == "" {
57
- s .BinaryName = "jaeger-v2"
58
- }
59
- configFile := s .ConfigFile
60
- if ! s .SkipStorageCleaner {
61
- configFile = createStorageCleanerConfig (t , s .ConfigFile , storage )
62
- }
63
- configFile , err := filepath .Abs (configFile )
64
- require .NoError (t , err , "Failed to get absolute path of the config file" )
65
- require .FileExists (t , configFile , "Config file does not exist at the resolved path" )
66
-
67
- t .Logf ("Starting %s in the background with config file %s" , s .BinaryName , configFile )
51
+ // Binary is a wrapper around exec.Cmd to help running binaries in tests.
52
+ type Binary struct {
53
+ Name string
54
+ exec.Cmd
55
+ }
68
56
57
+ func (b * Binary ) Start (t * testing.T ) {
69
58
outFile , err := os .OpenFile (
70
- filepath .Join (t .TempDir (), "jaeger_output_logs .txt" ),
59
+ filepath .Join (t .TempDir (), "output_logs .txt" ),
71
60
os .O_CREATE | os .O_WRONLY ,
72
61
os .ModePerm ,
73
62
)
74
63
require .NoError (t , err )
75
- t .Logf ("Writing the %s output logs into %s" , s . BinaryName , outFile .Name ())
64
+ t .Logf ("Writing the %s output logs into %s" , b . Name , outFile .Name ())
76
65
77
66
errFile , err := os .OpenFile (
78
- filepath .Join (t .TempDir (), "jaeger_error_logs .txt" ),
67
+ filepath .Join (t .TempDir (), "error_logs .txt" ),
79
68
os .O_CREATE | os .O_WRONLY ,
80
69
os .ModePerm ,
81
70
)
82
71
require .NoError (t , err )
83
- t .Logf ("Writing the %s error logs into %s" , s .BinaryName , errFile .Name ())
84
-
85
- cmd := exec.Cmd {
86
- Path : "./cmd/jaeger/jaeger" ,
87
- Args : []string {"jaeger" , "--config" , configFile },
88
- // Change the working directory to the root of this project
89
- // since the binary config file jaeger_query's ui_config points to
90
- // "./cmd/jaeger/config-ui.json"
91
- Dir : "../../../.." ,
92
- Stdout : outFile ,
93
- Stderr : errFile ,
94
- }
95
- t .Logf ("Running command: %v" , cmd .Args )
96
- require .NoError (t , cmd .Start ())
72
+ t .Logf ("Writing the %s error logs into %s" , b .Name , errFile .Name ())
73
+
74
+ b .Stdout = outFile
75
+ b .Stderr = errFile
76
+
77
+ t .Logf ("Running command: %v" , b .Args )
78
+ require .NoError (t , b .Cmd .Start ())
97
79
t .Cleanup (func () {
98
- if err := cmd .Process .Kill (); err != nil {
99
- t .Errorf ("Failed to kill %s process: %v" , s . BinaryName , err )
80
+ if err := b .Process .Kill (); err != nil {
81
+ t .Errorf ("Failed to kill %s process: %v" , b . Name , err )
100
82
}
101
83
if t .Failed () {
102
- // A Github Actions special annotation to create a foldable section
103
- // in the Github runner output.
84
+ // A special annotation to create a foldable section in the GitHub Actions runner output.
104
85
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines
105
- fmt .Printf ("::group::🚧 🚧 🚧 %s binary logs\n " , s . BinaryName )
86
+ fmt .Printf ("::group::🚧 🚧 🚧 %s binary logs\n " , b . Name )
106
87
outLogs , err := os .ReadFile (outFile .Name ())
107
88
if err != nil {
108
89
t .Errorf ("Failed to read output logs: %v" , err )
109
90
} else {
110
- fmt .Printf ("🚧 🚧 🚧 %s output logs:\n %s" , s . BinaryName , outLogs )
91
+ fmt .Printf ("🚧 🚧 🚧 %s output logs:\n %s" , b . Name , outLogs )
111
92
}
112
93
113
94
errLogs , err := os .ReadFile (errFile .Name ())
114
95
if err != nil {
115
96
t .Errorf ("Failed to read error logs: %v" , err )
116
97
} else {
117
- fmt .Printf ("🚧 🚧 🚧 %s error logs:\n %s" , s . BinaryName , errLogs )
98
+ fmt .Printf ("🚧 🚧 🚧 %s error logs:\n %s" , b . Name , errLogs )
118
99
}
119
100
// End of Github Actions foldable section annotation.
120
101
fmt .Println ("::endgroup::" )
121
102
}
122
103
})
104
+ }
105
+
106
+ // e2eInitialize starts the Jaeger-v2 collector with the provided config file,
107
+ // it also initialize the SpanWriter and SpanReader below.
108
+ // This function should be called before any of the tests start.
109
+ func (s * E2EStorageIntegration ) e2eInitialize (t * testing.T , storage string ) {
110
+ logger := zaptest .NewLogger (t , zaptest .WrapOptions (zap .AddCaller ()))
111
+ if s .BinaryName == "" {
112
+ s .BinaryName = "jaeger-v2"
113
+ }
114
+ configFile := s .ConfigFile
115
+ if ! s .SkipStorageCleaner {
116
+ configFile = createStorageCleanerConfig (t , s .ConfigFile , storage )
117
+ }
118
+ configFile , err := filepath .Abs (configFile )
119
+ require .NoError (t , err , "Failed to get absolute path of the config file" )
120
+ require .FileExists (t , configFile , "Config file does not exist at the resolved path" )
121
+
122
+ t .Logf ("Starting %s in the background with config file %s" , s .BinaryName , configFile )
123
+ cmd := Binary {
124
+ Name : s .BinaryName ,
125
+ Cmd : exec.Cmd {
126
+ Path : "./cmd/jaeger/jaeger" ,
127
+ Args : []string {"jaeger" , "--config" , configFile },
128
+ // Change the working directory to the root of this project
129
+ // since the binary config file jaeger_query's ui_config points to
130
+ // "./cmd/jaeger/config-ui.json"
131
+ Dir : "../../../.." ,
132
+ },
133
+ }
134
+ cmd .Start (t )
123
135
124
136
// Wait for the binary to start and become ready to serve requests.
125
137
require .Eventually (t , func () bool { return s .doHealthCheck (t ) },
0 commit comments