Skip to content

Commit 096726b

Browse files
committed
Merge branch 'issue_41_flasher_api' into issue_44_flasher_api
2 parents 2487115 + 0b31374 commit 096726b

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

pkg/flasherapi/flasherapi.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package flasherapi
1717

1818
import (
1919
"bufio"
20-
"context"
2120
"io"
2221
"log/slog"
2322
"strings"
@@ -29,8 +28,7 @@ const R0_IMAGE_VERSION_ID = "20250807-136"
2928

3029
// GetOSImageVersion returns the version of the OS image used in the board.
3130
// It is used by the AppLab to enforce image version compatibility.
32-
func GetOSImageVersion(ctx context.Context, conn remote.RemoteConn) string {
33-
31+
func GetOSImageVersion(conn remote.RemoteConn) string {
3432
f, err := conn.ReadFile("/etc/buildinfo")
3533
if err != nil {
3634
slog.Warn("Unable to read buildinfo file", "err", err, "using_default", R0_IMAGE_VERSION_ID)

pkg/flasherapi/flasherapi_test.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,62 @@
1212
// modify or otherwise use the software for commercial activities involving the
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
15-
1615
package flasherapi
1716

1817
import (
18+
"context"
19+
"io"
1920
"strings"
2021
"testing"
22+
23+
"github.com/stretchr/testify/require"
24+
25+
"github.com/arduino/arduino-app-cli/pkg/board/remote"
2126
)
2227

28+
// implements remote.RemoteConn
29+
type MockRemoteConn struct {
30+
ReadFileFunc func(path string) (io.ReadCloser, error)
31+
}
32+
33+
func (m *MockRemoteConn) ReadFile(path string) (io.ReadCloser, error) {
34+
return m.ReadFileFunc(path)
35+
}
36+
37+
// Empty definitions
38+
func (m *MockRemoteConn) List(path string) ([]remote.FileInfo, error) {
39+
return nil, nil
40+
}
41+
func (m *MockRemoteConn) MkDirAll(path string) error {
42+
return nil
43+
}
44+
func (m *MockRemoteConn) Remove(path string) error {
45+
return nil
46+
}
47+
func (m *MockRemoteConn) Stats(path string) (remote.FileInfo, error) {
48+
return remote.FileInfo{}, nil
49+
}
50+
func (m *MockRemoteConn) WriteFile(data io.Reader, path string) error {
51+
return nil
52+
}
53+
func (m *MockRemoteConn) GetCmd(cmd string, args ...string) remote.Cmder {
54+
return nil
55+
}
56+
func (m *MockRemoteConn) Forward(ctx context.Context, localPort int, remotePort int) error {
57+
return nil
58+
}
59+
func (m *MockRemoteConn) ForwardKillAll(ctx context.Context) error {
60+
return nil
61+
}
62+
func createBuildInfoConnection(imageVersion string) remote.RemoteConn {
63+
mockConn := MockRemoteConn{
64+
ReadFileFunc: func(path string) (io.ReadCloser, error) {
65+
return io.NopCloser(strings.NewReader(imageVersion)), nil
66+
},
67+
}
68+
return &mockConn
69+
}
70+
2371
func TestParseOSImageVersion(t *testing.T) {
2472
tests := []struct {
2573
name string
@@ -44,7 +92,6 @@ func TestParseOSImageVersion(t *testing.T) {
4492
found: false,
4593
},
4694
}
47-
4895
for _, tt := range tests {
4996
t.Run(tt.name, func(t *testing.T) {
5097
got, ok := parseOSImageVersion(strings.NewReader(tt.input))
@@ -54,3 +101,11 @@ func TestParseOSImageVersion(t *testing.T) {
54101
})
55102
}
56103
}
104+
105+
func TestGetOSImageVersion(t *testing.T) {
106+
const R0_IMAGE_VERSION_ID = "20250807-136"
107+
R0Version := createBuildInfoConnection(R0_IMAGE_VERSION_ID)
108+
AnotherVersion := createBuildInfoConnection("BUILD_ID=20250101-001")
109+
require.Equal(t, GetOSImageVersion(R0Version), R0_IMAGE_VERSION_ID)
110+
require.Equal(t, GetOSImageVersion(AnotherVersion), "20250101-001")
111+
}

0 commit comments

Comments
 (0)