feat(agent): package stable Go runtime for OpenWrt

This commit is contained in:
benya
2026-07-21 00:20:48 +03:00
parent e6236f505c
commit 01e0350cde
18 changed files with 461 additions and 38 deletions
+3 -3
View File
@@ -23,7 +23,7 @@ import (
"time"
)
const agentVersion = "0.5.0-go-preview"
const agentVersion = "0.5.0"
type config struct {
ServerURL string
@@ -249,7 +249,7 @@ func acquireLock(path string) (func(), error) {
if err := os.Mkdir(path, 0o700); err != nil {
return nil, fmt.Errorf("another rmm-agent instance is running")
}
return func() { _ = os.RemoveAll(path) }, nil
return func() { _ = os.Remove(path) }, nil
}
func enroll(ctx context.Context, client *http.Client, cfg *config) error {
@@ -485,7 +485,7 @@ func runCommand(ctx context.Context, cfg config, cmd command) (string, int) {
case "remote_ssh_close":
return remoteSSHCloseOutput(cfg, args)
default:
return fmt.Sprintf("go agent preview does not implement command %q yet; shell agent remains the production command runner\n", cmd.Type), 2
return fmt.Sprintf("rmm-agent does not implement command %q\n", cmd.Type), 2
}
}
+31 -1
View File
@@ -1,6 +1,36 @@
package main
import "testing"
import (
"errors"
"os"
"path/filepath"
"testing"
)
func TestAgentVersionIsStable(t *testing.T) {
if agentVersion != "0.5.0" {
t.Fatalf("unexpected agent version %q", agentVersion)
}
}
func TestAcquireLockRemovesDirectoryOnUnlock(t *testing.T) {
lockPath := filepath.Join(t.TempDir(), "rmm-agent.lock")
unlock, err := acquireLock(lockPath)
if err != nil {
t.Fatalf("acquireLock() error: %v", err)
}
if _, err := os.Stat(lockPath); err != nil {
t.Fatalf("lock directory was not created: %v", err)
}
if _, err := acquireLock(lockPath); err == nil {
t.Fatal("second acquireLock() unexpectedly succeeded")
}
unlock()
if _, err := os.Stat(lockPath); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("lock directory still exists after unlock: %v", err)
}
}
func TestParseIwinfoAssocList(t *testing.T) {
output := `AA:BB:CC:DD:EE:FF -49 dBm / -95 dBm (SNR 46) 210 ms ago