@@ -51,6 +51,8 @@ func TestNewOSBuildCmdNilOptions(t *testing.T) {
5151
5252func TestNewOSBuildCmdFullOptions (t * testing.T ) {
5353 mf := []byte (`{"real": "manifest"}` )
54+ _ , wp , err := os .Pipe ()
55+ assert .NoError (t , err )
5456 cmd := osbuild .NewOSBuildCmd (
5557 mf ,
5658 & osbuild.OSBuildOptions {
@@ -63,7 +65,7 @@ func TestNewOSBuildCmdFullOptions(t *testing.T) {
6365 Checkpoints : []string {"checkpoint-1" , "checkpoint-2" },
6466 ExtraEnv : []string {"EXTRA_ENV_1=1" , "EXTRA_ENV_2=2" },
6567 Monitor : osbuild .MonitorLog ,
66- MonitorFD : 10 ,
68+ MonitorFile : wp ,
6769 JSONOutput : true ,
6870 CacheMaxSize : 10 * datasizes .GiB ,
6971 },
@@ -89,7 +91,7 @@ func TestNewOSBuildCmdFullOptions(t *testing.T) {
8991 "--checkpoint" ,
9092 "checkpoint-2" ,
9193 "--monitor=LogMonitor" ,
92- "--monitor-fd=10 " ,
94+ "--monitor-fd=3 " ,
9395 "--json" ,
9496 },
9597 cmd .Args ,
@@ -101,6 +103,8 @@ func TestNewOSBuildCmdFullOptions(t *testing.T) {
101103 stdin , err := io .ReadAll (cmd .Stdin )
102104 assert .NoError (t , err )
103105 assert .Equal (t , mf , stdin )
106+
107+ assert .Equal (t , wp , cmd .ExtraFiles [0 ])
104108}
105109
106110func TestRunOSBuildJSONOutput (t * testing.T ) {
@@ -157,6 +161,44 @@ osbuild-stderr-output
157161 assert .Empty (t , stderr .Bytes ())
158162}
159163
164+ func TestRunOSBuildMonitor (t * testing.T ) {
165+ fakeOSBuildBinary := makeFakeOSBuild (t , `
166+ >&3 echo -n '{"some": "monitor"}'
167+
168+ if [ "$1" = "--version" ]; then
169+ echo '90000.0'
170+ else
171+ echo -n osbuild-stdout-output
172+ fi
173+ >&2 echo -n osbuild-stderr-output
174+ ` )
175+ restore := osbuild .MockOSBuildCmd (fakeOSBuildBinary )
176+ defer restore ()
177+
178+ rp , wp , err := os .Pipe ()
179+ assert .NoError (t , err )
180+ defer wp .Close ()
181+
182+ var stdout , stderr bytes.Buffer
183+ opts := & osbuild.OSBuildOptions {
184+ Stdout : & stdout ,
185+ Stderr : & stderr ,
186+ Monitor : osbuild .MonitorJSONSeq ,
187+ MonitorFile : wp ,
188+ }
189+
190+ // without json output set the result will be empty
191+ _ , err = osbuild .RunOSBuild (nil , opts )
192+ assert .NoError (t , err )
193+ assert .NoError (t , wp .Close ())
194+
195+ monitorOutput , err := io .ReadAll (rp )
196+ assert .NoError (t , err )
197+ assert .Equal (t , `{"some": "monitor"}` , string (monitorOutput ))
198+ assert .Equal (t , "osbuild-stdout-output" , stdout .String ())
199+ assert .Equal (t , "osbuild-stderr-output" , stderr .String ())
200+ }
201+
160202func TestSyncWriter (t * testing.T ) {
161203 var mu sync.Mutex
162204 var buf bytes.Buffer
0 commit comments