Skip to content

Commit 7979733

Browse files
committed
using a helper file
1 parent 8eae685 commit 7979733

File tree

4 files changed

+102
-87
lines changed

4 files changed

+102
-87
lines changed

.github/workflows/test-update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
env:
2929
GH_TOKEN: ${{ secrets.ARDUINOBOT_TOKEN }}
3030
run: |
31-
go test -v ./internal/testtools/deb_test.go --arch amd64
31+
go test -v ./internal/testtools/test_deb_update -- --arch amd64
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package testtools
2+
3+
import (
4+
"context"
5+
"flag"
6+
"fmt"
7+
"log"
8+
"testing"
9+
"time"
10+
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
var arch = flag.String("arch", "amd64", "target architecture")
15+
16+
func TestStableToUnstable(t *testing.T) {
17+
fmt.Printf("***** ARCH %s ***** \n", *arch)
18+
tagAppCli := FetchDebPackage(t, "arduino-app-cli", "latest", *arch)
19+
FetchDebPackage(t, "arduino-router", "latest", *arch)
20+
majorTag := majorTag(t, tagAppCli)
21+
_ = minorTag(t, tagAppCli)
22+
23+
fmt.Printf("Updating from stable version %s to unstable version %s \n", tagAppCli, majorTag)
24+
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")
38+
}
39+
40+
func TestClientUpdate(t *testing.T) {
41+
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)
46+
47+
fmt.Println("**** RUN docker image *****")
48+
runDockerContainer(t, "apt-test-update", "apt-test-update-image")
49+
preUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
50+
51+
runDockerDaemon(t, "apt-test-update")
52+
time.Sleep(5 * time.Second) //wait for the daemon to be fully started
53+
status := putUpdateRequest(t, "http://127.0.0.1:8800/v1/system/update/apply")
54+
fmt.Printf("Response status: %s\n", status)
55+
56+
itr := NewSSEClient(context.Background(), "GET", "http://localhost:8800/v1/system/update/events")
57+
58+
for event, err := range itr {
59+
if err != nil {
60+
log.Printf("Error receiving SSE event: %v", err)
61+
}
62+
fmt.Printf("Received event: ID=%s, Event=%s, Data=%s\n", event.ID, event.Event, string(event.Data))
63+
if string(event.Data) == "Download complete" {
64+
fmt.Println("✅ Download complete — exiting successfully.")
65+
}
66+
}
67+
68+
postUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
69+
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+
}
75+
76+
func TestUnstableToStable(t *testing.T) {
77+
tagAppCli := FetchDebPackage(t, "arduino-app-cli", "latest", *arch)
78+
FetchDebPackage(t, "arduino-router", "latest", *arch)
79+
minorTag := minorTag(t, tagAppCli)
80+
moveDeb(t, "build/stable", "build/", "arduino-app-cli", tagAppCli, *arch)
81+
82+
fmt.Printf("Updating from unstable version %s to stable version %s \n", minorTag, tagAppCli)
83+
fmt.Printf("Building local deb version %s \n", minorTag)
84+
buildDebVersion(t, minorTag, *arch)
85+
moveDeb(t, "build/", "build/stable", "arduino-app-cli", minorTag, *arch)
86+
87+
fmt.Printf("Check folder structure and deb downloaded\n")
88+
ls(t)
89+
90+
fmt.Println("**** BUILD docker image *****")
91+
buildDockerImage(t, "test.Dockerfile", "test-apt-update-unstable-image", *arch)
92+
fmt.Println("**** RUN docker image *****")
93+
runDockerContainer(t, "test-apt-update-unstable", "test-apt-update-unstable-image")
94+
preUpdateVersion := runDockerSystemVersion(t, "apt-test-update-unstable")
95+
runDockerSystemUpdate(t, "apt-test-update-unstable")
96+
postUpdateVersion := runDockerSystemVersion(t, "apt-test-update-unstable")
97+
runDockerCleanUp(t, "apt-test-update-unstable")
98+
require.Equal(t, preUpdateVersion, "Arduino App CLI "+tagAppCli+"\n")
99+
require.Equal(t, postUpdateVersion, "Arduino App CLI "+minorTag+"\n")
100+
101+
}

internal/testtools/deb_test.go renamed to internal/testtools/test_deb_update/helpers.go

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bufio"
55
"bytes"
66
"context"
7-
"flag"
87
"fmt"
98
"io"
109
"iter"
@@ -16,93 +15,8 @@ import (
1615
"strconv"
1716
"strings"
1817
"testing"
19-
"time"
20-
21-
"github.com/stretchr/testify/require"
2218
)
2319

24-
var arch = flag.String("arch", "amd64", "target architecture")
25-
26-
func TestStableToUnstable(t *testing.T) {
27-
fmt.Printf("***** ARCH %s ***** \n", *arch)
28-
tagAppCli := FetchDebPackage(t, "arduino-app-cli", "latest", *arch)
29-
FetchDebPackage(t, "arduino-router", "latest", *arch)
30-
majorTag := majorTag(t, tagAppCli)
31-
_ = minorTag(t, tagAppCli)
32-
33-
fmt.Printf("Updating from stable version %s to unstable version %s \n", tagAppCli, majorTag)
34-
fmt.Printf("Building local deb version %s \n", majorTag)
35-
buildDebVersion(t, majorTag, *arch)
36-
fmt.Printf("Check folder structure and deb downloaded\n")
37-
ls(t)
38-
fmt.Println("**** BUILD docker image *****")
39-
buildDockerImage(t, "test.Dockerfile", "apt-test-update-image", *arch)
40-
fmt.Println("**** RUN docker image *****")
41-
runDockerContainer(t, "apt-test-update", "apt-test-update-image")
42-
preUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
43-
runDockerSystemUpdate(t, "apt-test-update")
44-
postUpdateVersion := runDockerSystemVersion(t, "apt-test-update")
45-
runDockerCleanUp(t, "apt-test-update")
46-
require.Equal(t, preUpdateVersion, "Arduino App CLI "+tagAppCli+"\n")
47-
require.Equal(t, postUpdateVersion, "Arduino App CLI "+majorTag+"\n")
48-
}
49-
50-
func TestClientUpdate(t *testing.T) {
51-
52-
fmt.Println("**** BUILD docker image *****")
53-
buildDockerImage(t, "test.Dockerfile", "apt-test-update-image", *arch)
54-
fmt.Println("**** RUN docker image *****")
55-
runDockerContainer(t, "apt-test-update", "apt-test-update-image")
56-
//Start the daemon
57-
runDockerDaemon(t, "apt-test-update")
58-
time.Sleep(5 * time.Second) //wait for the daemon to be fully started
59-
//PUT on the /v1/updates/apply
60-
status := putUpdateRequest(t, "http://127.0.0.1:8800/v1/system/update/apply")
61-
fmt.Printf("Response status: %s\n", status)
62-
63-
itr := NewSSEClient(context.Background(), "GET", "http://localhost:8800/v1/system/update/events")
64-
65-
for event, err := range itr {
66-
if err != nil {
67-
log.Fatalf("Error receiving SSE event: %v", err)
68-
}
69-
fmt.Printf("Received event: ID=%s, Event=%s, Data=%s\n", event.ID, event.Event, string(event.Data))
70-
if string(event.Data) == "Download complete" {
71-
break
72-
}
73-
}
74-
75-
runDockerCleanUp(t, "apt-test-update")
76-
77-
}
78-
79-
func TestUnstableToStable(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-
moveDeb(t, "build/stable", "build/", "arduino-app-cli", tagAppCli, *arch)
84-
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-
buildDebVersion(t, minorTag, *arch)
88-
moveDeb(t, "build/", "build/stable", "arduino-app-cli", minorTag, *arch)
89-
90-
fmt.Printf("Check folder structure and deb downloaded\n")
91-
ls(t)
92-
93-
fmt.Println("**** BUILD docker image *****")
94-
buildDockerImage(t, "test.Dockerfile", "test-apt-update-unstable-image", *arch)
95-
fmt.Println("**** RUN docker image *****")
96-
runDockerContainer(t, "test-apt-update-unstable", "test-apt-update-unstable-image")
97-
preUpdateVersion := runDockerSystemVersion(t, "apt-test-update-unstable")
98-
runDockerSystemUpdate(t, "apt-test-update-unstable")
99-
postUpdateVersion := runDockerSystemVersion(t, "apt-test-update-unstable")
100-
runDockerCleanUp(t, "apt-test-update-unstable")
101-
require.Equal(t, preUpdateVersion, "Arduino App CLI "+tagAppCli+"\n")
102-
require.Equal(t, postUpdateVersion, "Arduino App CLI "+minorTag+"\n")
103-
104-
}
105-
10620
func FetchDebPackage(t *testing.T, repo, version, arch string) string {
10721
t.Helper()
10822

0 commit comments

Comments
 (0)