Skip to content

Commit ca1d355

Browse files
committed
path in the building
1 parent a9c764d commit ca1d355

File tree

2 files changed

+84
-92
lines changed

2 files changed

+84
-92
lines changed

internal/testtools/test_deb_update/deb_test.go

Lines changed: 75 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -15,83 +15,87 @@ var arch = flag.String("arch", "amd64", "target architecture")
1515

1616
func 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

7779
func 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

internal/testtools/test_deb_update/helpers.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"time"
2020
)
2121

22-
func FetchDebPackage(t *testing.T, repo, version, arch string) string {
22+
func FetchDebPackage(t *testing.T, path, repo, version, arch string) string {
2323
t.Helper()
2424

2525
cmd := exec.Command(
@@ -43,7 +43,7 @@ func FetchDebPackage(t *testing.T, repo, version, arch string) string {
4343
tag := fields[0]
4444
tagPath := strings.TrimPrefix(tag, "v")
4545

46-
debFile := fmt.Sprintf("build/stable/%s_%s-1_%s.deb", repo, tagPath, arch)
46+
debFile := fmt.Sprintf("%s/%s_%s-1_%s.deb", path, repo, tagPath, arch)
4747
fmt.Println(debFile)
4848
if _, err := os.Stat(debFile); err == nil {
4949
fmt.Printf("✅ %s already exists, skipping download.\n", debFile)
@@ -55,7 +55,7 @@ func FetchDebPackage(t *testing.T, repo, version, arch string) string {
5555
tag,
5656
"--repo", "github.com/arduino/"+repo,
5757
"--pattern", "*",
58-
"--dir", "./build/stable",
58+
"--dir", path,
5959
)
6060

6161
out, err := cmd2.CombinedOutput()
@@ -67,13 +67,13 @@ func FetchDebPackage(t *testing.T, repo, version, arch string) string {
6767

6868
}
6969

70-
func buildDebVersion(t *testing.T, tagVersion, arch string) {
70+
func buildDebVersion(t *testing.T, storePath, tagVersion, arch string) {
7171
t.Helper()
7272
cwd, err := os.Getwd()
7373
if err != nil {
7474
panic(err)
7575
}
76-
outputDir := filepath.Join(cwd, "build")
76+
outputDir := filepath.Join(cwd, storePath)
7777

7878
cmd := exec.Command(
7979
"go", "tool", "task", "build-deb",
@@ -207,7 +207,7 @@ func runDockerSystemUpdate(t *testing.T, containerName string) {
207207

208208
}
209209

210-
func runDockerDaemon(t *testing.T, containerName string) {
210+
func runDockerDaemon(t *testing.T, containerName string) string {
211211
t.Helper()
212212

213213
cmd := exec.Command(
@@ -222,8 +222,7 @@ func runDockerDaemon(t *testing.T, containerName string) {
222222
log.Fatalf("command failed: %v\n Output: %s", err, output)
223223
}
224224

225-
fmt.Printf("Daemon started: %s\n", output)
226-
225+
return string(output)
227226
}
228227

229228
func runDockerCleanUp(t *testing.T, containerName string) {
@@ -307,9 +306,6 @@ func putUpdateRequest(t *testing.T, url string) string {
307306
}
308307
defer resp.Body.Close()
309308

310-
fmt.Printf("Response status: %s\n", resp.Status)
311-
312-
// Check status code
313309
return resp.Status
314310
}
315311
func NewSSEClient(ctx context.Context, method, url string) iter.Seq2[Event, error] {
@@ -368,9 +364,9 @@ type Event struct {
368364
}
369365

370366
// WaitForPort waits until a TCP port is open or fails after timeout.
371-
func WaitForPort(t *testing.T, host string, port int, timeout time.Duration) {
367+
func WaitForPort(t *testing.T, host string, port string, timeout time.Duration) {
372368
t.Helper()
373-
addr := fmt.Sprintf("%s:%d", host, port)
369+
addr := fmt.Sprintf("%s:%s", host, port)
374370

375371
deadline := time.Now().Add(timeout)
376372
for time.Now().Before(deadline) {

0 commit comments

Comments
 (0)