@@ -2,10 +2,12 @@ package testtools
22
33import (
44 "bytes"
5+ "context"
56 "flag"
67 "fmt"
78 "io"
89 "log"
10+ "net/http"
911 "os"
1012 "os/exec"
1113 "path/filepath"
@@ -37,9 +39,36 @@ func TestStableToUnstable(t *testing.T) {
3739 preUpdateVersion := runDockerSystemVersion (t , "apt-test-update" )
3840 runDockerSystemUpdate (t , "apt-test-update" )
3941 postUpdateVersion := runDockerSystemVersion (t , "apt-test-update" )
40- runDockerCleanUp (t , "apt-test-update" )
42+ // runDockerCleanUp(t, "apt-test-update")
4143 require .Equal (t , preUpdateVersion , "Arduino App CLI " + tagAppCli + "\n " )
4244 require .Equal (t , postUpdateVersion , "Arduino App CLI " + majorTag + "\n " )
45+ }
46+
47+ func TestClientUpdate (t * testing.T ) {
48+
49+ fmt .Printf ("Check folder structure and deb downloaded\n " )
50+ ls (t )
51+ fmt .Println ("**** BUILD docker image *****" )
52+ buildDockerImage (t , "test.Dockerfile" , "apt-test-update-image" , * arch )
53+ fmt .Println ("**** RUN docker image *****" )
54+ runDockerContainer (t , "apt-test-update" , "apt-test-update-image" )
55+ //Start the daemon
56+ runDockerDaemon (t , "apt-test-update" )
57+ //PUT on the /v1/updates/apply
58+ status := putUpdateRequest (t , "http://localhost:8080/v1/system/update/apply" )
59+ fmt .Printf ("Response status: %s\n " , status )
60+ //ClientSSE
61+
62+ itr := NewSSEClient (context .Background (), "GET" , "http://localhost:8080/v1/system/update/apply" )
63+
64+ for event , err := range itr {
65+ if err != nil {
66+ log .Fatalf ("Error receiving SSE event: %v" , err )
67+ }
68+ fmt .Printf ("Received event: ID=%s, Event=%s, Data=%s\n " , event .ID , event .Event , string (event .Data ))
69+ }
70+
71+ runDockerCleanUp (t , "apt-test-update" )
4372
4473}
4574
@@ -60,7 +89,7 @@ func TestUnstableToStable(t *testing.T) {
6089 fmt .Println ("**** BUILD docker image *****" )
6190 buildDockerImage (t , "test.Dockerfile" , "test-apt-update-unstable-image" , * arch )
6291 fmt .Println ("**** RUN docker image *****" )
63- runDockerContainer (t , "test-apt-update-unstable-image " , "apt- test-update-unstable" )
92+ runDockerContainer (t , "test-apt-update-unstable" , "test-apt- update-unstable-image " )
6493 preUpdateVersion := runDockerSystemVersion (t , "apt-test-update-unstable" )
6594 runDockerSystemUpdate (t , "apt-test-update-unstable" )
6695 postUpdateVersion := runDockerSystemVersion (t , "apt-test-update-unstable" )
@@ -337,3 +366,26 @@ func rm(t *testing.T, pathFile string) {
337366 fmt .Printf ("📦 Removed %s\n " , pathFile )
338367
339368}
369+
370+ func putUpdateRequest (t * testing.T , url string ) string {
371+
372+ // Create PUT request
373+ req , err := http .NewRequest (http .MethodPut , url , nil )
374+ if err != nil {
375+ log .Fatalf ("Error creating request: %v" , err )
376+ }
377+
378+ // Optional: add headers if your API needs them
379+ req .Header .Set ("Content-Type" , "application/json" )
380+
381+ // Send the request
382+ client := & http.Client {}
383+ resp , err := client .Do (req )
384+ if err != nil {
385+ log .Fatalf ("Error making request: %v" , err )
386+ }
387+ defer resp .Body .Close ()
388+
389+ // Check status code
390+ return resp .Status
391+ }
0 commit comments