@@ -15,83 +15,87 @@ var arch = flag.String("arch", "amd64", "target architecture")
1515
1616func TestStableToUnstable (t * testing.T ) {
1717 fmt .Printf ("***** ARCH %s ***** \n " , * arch )
18- tagAppCli := FetchDebPackage (t , "arduino-app-cli" , "latest" , * arch )
19- FetchDebPackage (t , "arduino-router" , "latest" , * arch )
18+ tagAppCli := FetchDebPackage (t , "build/stable" , " arduino-app-cli" , "latest" , * arch )
19+ FetchDebPackage (t , "build/stable" , " arduino-router" , "latest" , * arch )
2020 majorTag := majorTag (t , tagAppCli )
2121 _ = minorTag (t , tagAppCli )
22-
2322 fmt .Printf ("Updating from stable version %s to unstable version %s \n " , tagAppCli , majorTag )
2423 fmt .Printf ("Building local deb version %s \n " , majorTag )
25- buildDebVersion (t , majorTag , * arch )
26- // fmt.Printf("Check folder structure and deb downloaded\n")
27- // ls(t)
28- // fmt.Println("**** BUILD docker image *****")
29- // buildDockerImage(t, "test.Dockerfile", "apt-test-update-image", *arch)
30- // fmt.Println("**** RUN docker image *****")
31- // runDockerContainer(t, "apt-test-update", "apt-test-update-image")
32- // preUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
33- // runDockerSystemUpdate(t, "apt-test-update")
34- // postUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
35- // runDockerCleanUp(t, "apt-test-update")
36- // require.Equal(t, preUpdateVersion, "Arduino App CLI "+tagAppCli+"\n")
37- // require.Equal(t, postUpdateVersion, "Arduino App CLI "+majorTag+"\n")
24+ buildDebVersion (t , "build" , majorTag , * arch )
25+ fmt .Printf ("Check folder structure and deb downloaded\n " )
26+ ls (t )
27+ fmt .Println ("**** BUILD docker image *****" )
28+ buildDockerImage (t , "test.Dockerfile" , "apt-test-update-image" , * arch )
29+ fmt .Println ("**** RUN docker image *****" )
30+ runDockerContainer (t , "apt-test-update" , "apt-test-update-image" )
31+ preUpdateVersion := runDockerSystemVersion (t , "apt-test-update" )
32+ runDockerSystemUpdate (t , "apt-test-update" )
33+ postUpdateVersion := runDockerSystemVersion (t , "apt-test-update" )
34+ runDockerCleanUp (t , "apt-test-update" )
35+ require .Equal (t , preUpdateVersion , "Arduino App CLI " + tagAppCli + "\n " )
36+ require .Equal (t , postUpdateVersion , "Arduino App CLI " + majorTag + "\n " )
3837}
3938
40- // func TestClientUpdateStU(t *testing.T) {
39+ func TestClientUpdateStU (t * testing.T ) {
4140
42- // fmt.Printf("***** ARCH %s ***** \n", *arch)
43- // tagAppCli := FetchDebPackage(t, "arduino-app-cli", "latest", *arch)
44- // FetchDebPackage(t, "arduino-router", "latest", *arch)
45- // majorTag := majorTag(t, tagAppCli)
41+ fmt .Printf ("***** ARCH %s ***** \n " , * arch )
42+ tagAppCli := FetchDebPackage (t , "build/stable" , "arduino-app-cli" , "latest" , * arch )
43+ FetchDebPackage (t , "build/stable" , "arduino-router" , "latest" , * arch )
44+ majorTag := majorTag (t , tagAppCli )
4645
47- // fmt.Println("**** RUN docker image *****")
48- // runDockerContainer(t, "apt-test-update", "apt-test-update-image")
49- // preUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
46+ fmt .Println ("**** RUN docker image *****" )
47+ runDockerContainer (t , "apt-test-update" , "apt-test-update-image" )
48+ preUpdateVersion := runDockerSystemVersion (t , "apt-test-update" )
5049
51- // runDockerDaemon(t, "apt-test-update")
52- // WaitForPort(t, "127.0.0.1", 8800, 5*time.Second)
50+ status := runDockerDaemon (t , "apt-test-update" )
51+ WaitForPort (t , "127.0.0.1" , " 8800" , 5 * time .Second )
5352
54- // status := putUpdateRequest(t, "http://127.0.0.1:8800/v1/system/update/apply")
55- // fmt.Printf("Response status: %s\n", status)
53+ status = putUpdateRequest (t , "http://127.0.0.1:8800/v1/system/update/apply" )
54+ if status != "202 Accepted" {
55+ log .Fatalf ("Error putting update request: %s" , status )
56+ }
5657
57- // itr := NewSSEClient(context.Background(), "GET", "http://localhost:8800/v1/system/update/events")
58+ itr := NewSSEClient (context .Background (), "GET" , "http://localhost:8800/v1/system/update/events" )
5859
59- // for event, err := range itr {
60- // if err != nil {
61- // log.Printf("Error receiving SSE event: %v", err)
62- // }
63- // fmt.Printf("Received event: ID=%s, Event=%s, Data=%s\n", event.ID, event.Event, string(event.Data))
64- // if string(event.Data) == "Download complete" {
65- // fmt.Println("✅ Download complete — exiting successfully.")
66- // }
67- // }
60+ for event , err := range itr {
61+ if err != nil {
62+ log .Printf ("Error receiving SSE event: %v" , err )
63+ }
64+ fmt .Printf ("Received event: ID=%s, Event=%s, Data=%s\n " , event .ID , event .Event , string (event .Data ))
65+ if string (event .Data ) == "Download complete" {
66+ fmt .Println ("✅ Download complete — exiting successfully." )
67+ break
68+ }
69+ }
6870
69- // postUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
71+ postUpdateVersion := runDockerSystemVersion (t , "apt-test-update" )
7072
71- // require.Equal(t, preUpdateVersion, "Arduino App CLI "+tagAppCli+"\n")
72- // require.Equal(t, postUpdateVersion, "Arduino App CLI "+majorTag+"\n")
73- // runDockerCleanUp(t, "apt-test-update")
73+ require .Equal (t , preUpdateVersion , "Arduino App CLI " + tagAppCli + "\n " )
74+ require .Equal (t , postUpdateVersion , "Arduino App CLI " + majorTag + "\n " )
75+ runDockerCleanUp (t , "apt-test-update" )
7476
75- // }
77+ }
7678
7779func TestUnstableToStable (t * testing.T ) {
7880
81+ fmt .Printf ("***** ARCH %s ***** \n " , * arch )
82+ tagAppCli := FetchDebPackage (t , "build" , "arduino-app-cli" , "latest" , * arch )
83+ FetchDebPackage (t , "build/stable" , "arduino-router" , "latest" , * arch )
84+ minorTag := minorTag (t , tagAppCli )
85+ //Move the stable package to the build (unstable) folder
86+ //moveDeb(t, "build/stable", "build/", "arduino-app-cli", tagAppCli, *arch)
87+ fmt .Printf ("Updating from unstable version %s to stable version %s \n " , minorTag , tagAppCli )
88+ fmt .Printf ("Building local deb version %s \n " , minorTag )
89+ //Build unstable with a minor tag w.r.t stable
90+ buildDebVersion (t , "build/stable" , minorTag , * arch )
91+ //Move the unstable package to the stable folder
92+ //moveDeb(t, "build/", "build/stable", "arduino-app-cli", minorTag, *arch)
93+ //fmt.Printf("Check folder structure and deb downloaded\n")
94+ //ls(t)
95+ fmt .Println ("**** BUILD docker image *****" )
96+ buildDockerImage (t , "test.Dockerfile" , "test-apt-update-unstable-image" , * arch )
7997 t .Run ("CLI Update Testing" , func (t * testing.T ) {
80- tagAppCli := FetchDebPackage (t , "arduino-app-cli" , "latest" , * arch )
81- FetchDebPackage (t , "arduino-router" , "latest" , * arch )
82- minorTag := minorTag (t , tagAppCli )
83- //Move the stable package to the build (unstable) folder
84- moveDeb (t , "build/stable" , "build/" , "arduino-app-cli" , tagAppCli , * arch )
85- fmt .Printf ("Updating from unstable version %s to stable version %s \n " , minorTag , tagAppCli )
86- fmt .Printf ("Building local deb version %s \n " , minorTag )
87- //Build unstable with a minor tag w.r.t stable
88- buildDebVersion (t , minorTag , * arch )
89- //Move the unstable package to the stable folder
90- moveDeb (t , "build/" , "build/stable" , "arduino-app-cli" , minorTag , * arch )
91- fmt .Printf ("Check folder structure and deb downloaded\n " )
92- ls (t )
93- fmt .Println ("**** BUILD docker image *****" )
94- buildDockerImage (t , "test.Dockerfile" , "test-apt-update-unstable-image" , * arch )
98+
9599 fmt .Println ("**** RUN docker image *****" )
96100 runDockerContainer (t , "apt-test-update-unstable" , "test-apt-update-unstable-image" )
97101 preUpdateVersion := runDockerSystemVersion (t , "apt-test-update-unstable" )
@@ -103,25 +107,16 @@ func TestUnstableToStable(t *testing.T) {
103107 })
104108
105109 t .Run ("Client Daemon Request Testing" , func (t * testing.T ) {
106- tagAppCli := FetchDebPackage (t , "arduino-app-cli" , "latest" , * arch )
107- FetchDebPackage (t , "arduino-router" , "latest" , * arch )
108- minorTag := minorTag (t , tagAppCli )
109- //Move the stable package to the build (unstable) folder
110- moveDeb (t , "build/stable" , "build/" , "arduino-app-cli" , tagAppCli , * arch )
111- fmt .Printf ("Updating from unstable version %s to stable version %s \n " , minorTag , tagAppCli )
112- fmt .Printf ("Building local deb version %s \n " , minorTag )
113- //Build unstable with a minor tag w.r.t stable
114- buildDebVersion (t , minorTag , * arch )
115- //Move the unstable package to the stable folder
116- moveDeb (t , "build/" , "build/stable" , "arduino-app-cli" , minorTag , * arch )
117- fmt .Printf ("Check folder structure and deb downloaded\n " )
118110 fmt .Println ("**** RUN docker image *****" )
119111 runDockerContainer (t , "apt-test-update-unstable" , "test-apt-update-unstable-image" )
120112 preUpdateVersion := runDockerSystemVersion (t , "apt-test-update-unstable" )
121- runDockerDaemon (t , "apt-test-update-unstable " )
122- WaitForPort (t , "127.0.0.1" , 8800 , 5 * time .Second )
123- status := putUpdateRequest (t , "http://127.0.0.1:8800/v1/system/update/apply" )
124- fmt .Printf ("Response status: %s\n " , status )
113+ status := runDockerDaemon (t , "apt-test-update-unstable" )
114+ WaitForPort (t , "127.0.0.1" , "8800" , 5 * time .Second )
115+
116+ status = putUpdateRequest (t , "http://127.0.0.1:8800/v1/system/update/apply" )
117+ if status != "202 Accepted" {
118+ log .Fatalf ("Error putting update request: %s" , status )
119+ }
125120
126121 itr := NewSSEClient (context .Background (), "GET" , "http://localhost:8800/v1/system/update/events" )
127122
@@ -130,15 +125,16 @@ func TestUnstableToStable(t *testing.T) {
130125 log .Printf ("Error receiving SSE event: %v" , err )
131126 }
132127 fmt .Printf ("Received event: ID=%s, Event=%s, Data=%s\n " , event .ID , event .Event , string (event .Data ))
133- if string (event .Data ) == "Download complete" {
134- fmt .Println ("✅ Download complete — exiting successfully." )
128+ if string (event .Data ) == "Upgrade completed successfully" {
129+ fmt .Println ("✅ exiting successfully." )
130+ break
135131 }
136132 }
137133
138- postUpdateVersion := runDockerSystemVersion (t , "apt-test-update" )
134+ postUpdateVersion := runDockerSystemVersion (t , "apt-test-update-unstable " )
139135 runDockerCleanUp (t , "apt-test-update-unstable" )
140- require .Equal (t , preUpdateVersion , "Arduino App CLI " + tagAppCli + "\n " )
141- require .Equal (t , postUpdateVersion , "Arduino App CLI " + minorTag + "\n " )
136+ require .Equal (t , preUpdateVersion , "Arduino App CLI " + minorTag + "\n " )
137+ require .Equal (t , postUpdateVersion , "Arduino App CLI " + tagAppCli + "\n " )
142138
143139 })
144140
0 commit comments