Skip to content

Commit 31553a5

Browse files
committed
test rebase
1 parent 380c48c commit 31553a5

File tree

2 files changed

+64
-42
lines changed

2 files changed

+64
-42
lines changed

internal/testtools/test_deb_update/deb_test.go

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,61 +19,59 @@ func TestStableToUnstable(t *testing.T) {
1919
FetchDebPackage(t, "build/stable", "arduino-router", "latest", *arch)
2020
majorTag := majorTag(t, tagAppCli)
2121
_ = minorTag(t, tagAppCli)
22+
2223
fmt.Printf("Updating from stable version %s to unstable version %s \n", tagAppCli, majorTag)
2324
fmt.Printf("Building local deb version %s \n", majorTag)
2425
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")
37-
}
3826

39-
func TestClientUpdateStU(t *testing.T) {
27+
t.Run("CLI Update Testing", func(t *testing.T) {
4028

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)
29+
fmt.Printf("Check folder structure and deb downloaded\n")
30+
ls(t)
31+
fmt.Println("**** BUILD docker image *****")
32+
buildDockerImage(t, "test.Dockerfile", "apt-test-update-image", *arch)
33+
fmt.Println("**** RUN docker image *****")
34+
runDockerContainer(t, "apt-test-update", "apt-test-update-image")
35+
preUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
36+
runDockerSystemUpdate(t, "apt-test-update")
37+
postUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
38+
runDockerCleanUp(t, "apt-test-update")
39+
require.Equal(t, preUpdateVersion, "Arduino App CLI "+tagAppCli+"\n")
40+
require.Equal(t, postUpdateVersion, "Arduino App CLI "+majorTag+"\n")
41+
})
4542

46-
fmt.Println("**** RUN docker image *****")
47-
runDockerContainer(t, "apt-test-update", "apt-test-update-image")
48-
preUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
43+
t.Run("Client Daemon Request Testing", func(t *testing.T) {
44+
runDockerContainer(t, "apt-test-update", "apt-test-update-image")
45+
preUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
4946

50-
status := runDockerDaemon(t, "apt-test-update")
51-
WaitForPort(t, "127.0.0.1", "8800", 5*time.Second)
47+
status := runDockerDaemon(t, "apt-test-update")
48+
WaitForPort(t, "127.0.0.1", "8800", 5*time.Second)
5249

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-
}
50+
status = putUpdateRequest(t, "http://127.0.0.1:8800/v1/system/update/apply")
51+
if status != "202 Accepted" {
52+
log.Fatalf("Error putting update request: %s", status)
53+
}
5754

58-
itr := NewSSEClient(context.Background(), "GET", "http://localhost:8800/v1/system/update/events")
55+
itr := NewSSEClient(context.Background(), "GET", "http://localhost:8800/v1/system/update/events")
5956

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
57+
for event, err := range itr {
58+
if err != nil {
59+
log.Printf("Error receiving SSE event: %v", err)
60+
}
61+
fmt.Printf("Received event: ID=%s, Event=%s, Data=%s\n", event.ID, event.Event, string(event.Data))
62+
if string(event.Data) == "Download complete" {
63+
fmt.Println("✅ Download complete — exiting successfully.")
64+
break
65+
}
6866
}
69-
}
70-
71-
postUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
7267

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")
68+
postUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
7669

70+
require.Equal(t, preUpdateVersion, "Arduino App CLI "+tagAppCli+"\n")
71+
require.Equal(t, postUpdateVersion, "Arduino App CLI "+majorTag+"\n")
72+
runDockerCleanUp(t, "apt-test-update")
73+
})
74+
rmrf(t, "build")
7775
}
7876

7977
func TestUnstableToStable(t *testing.T) {

internal/testtools/test_deb_update/helpers.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,30 @@ func putUpdateRequest(t *testing.T, url string) string {
308308

309309
return resp.Status
310310
}
311+
312+
func rmrf(t *testing.T, pathFile string) {
313+
t.Helper()
314+
// Check if the folder exists
315+
if _, err := os.Stat(pathFile); os.IsNotExist(err) {
316+
fmt.Println("No build directory found.")
317+
return
318+
}
319+
320+
// Run the Linux command to remove it
321+
cmd := exec.Command("rm", "-rf", pathFile)
322+
cmd.Stdout = os.Stdout
323+
cmd.Stderr = os.Stderr
324+
325+
fmt.Println("Removing build directory...")
326+
327+
if err := cmd.Run(); err != nil {
328+
fmt.Fprintf(os.Stderr, "Error removing build folder: %v\n", err)
329+
os.Exit(1)
330+
}
331+
332+
fmt.Println("Build directory removed successfully.")
333+
}
334+
311335
func NewSSEClient(ctx context.Context, method, url string) iter.Seq2[Event, error] {
312336
return func(yield func(Event, error) bool) {
313337
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

0 commit comments

Comments
 (0)