mirror of
https://github.com/harivansh-afk/betterNAS.git
synced 2026-04-17 23:01:32 +00:00
Stabilize the node agent runtime loop.
Keep the NAS-side runtime bounded to the configured export path, make WebDAV and registration behavior env-driven, and add runtime coverage so the first storage loop can be verified locally. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
a7f85f4871
commit
273af4b0ab
14 changed files with 3294 additions and 36 deletions
95
apps/node-agent/internal/nodeagent/app_test.go
Normal file
95
apps/node-agent/internal/nodeagent/app_test.go
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package nodeagent
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewRejectsMissingExportDirectory(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
exportPath := filepath.Join(t.TempDir(), "missing-export")
|
||||
|
||||
_, err := New(Config{
|
||||
ExportPath: exportPath,
|
||||
ListenAddress: defaultListenAddress(defaultPort),
|
||||
}, log.New(io.Discard, "", 0))
|
||||
if err == nil {
|
||||
t.Fatal("expected missing export directory to fail")
|
||||
}
|
||||
|
||||
if !strings.Contains(err.Error(), "does not exist") {
|
||||
t.Fatalf("error = %q, want missing-directory message", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRejectsFileExportPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
exportPath := filepath.Join(t.TempDir(), "export.txt")
|
||||
if err := os.WriteFile(exportPath, []byte("not a directory"), 0o644); err != nil {
|
||||
t.Fatalf("write export file: %v", err)
|
||||
}
|
||||
|
||||
_, err := New(Config{
|
||||
ExportPath: exportPath,
|
||||
ListenAddress: defaultListenAddress(defaultPort),
|
||||
}, log.New(io.Discard, "", 0))
|
||||
if err == nil {
|
||||
t.Fatal("expected file export path to fail")
|
||||
}
|
||||
|
||||
if !strings.Contains(err.Error(), "is not a directory") {
|
||||
t.Fatalf("error = %q, want not-a-directory message", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRejectsInvalidListenAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := New(Config{
|
||||
ExportPath: t.TempDir(),
|
||||
ListenAddress: "localhost",
|
||||
}, log.New(io.Discard, "", 0))
|
||||
if err == nil {
|
||||
t.Fatal("expected invalid listen address to fail")
|
||||
}
|
||||
|
||||
if !strings.Contains(err.Error(), listenAddressEnvKey) {
|
||||
t.Fatalf("error = %q, want %q", err.Error(), listenAddressEnvKey)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewAcceptsLoopbackListenAddressByDefault(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := New(Config{
|
||||
ExportPath: t.TempDir(),
|
||||
ListenAddress: defaultListenAddress(defaultPort),
|
||||
}, log.New(io.Discard, "", 0))
|
||||
if err != nil {
|
||||
t.Fatalf("new app: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRejectsRegistrationWithoutMachineID(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := New(Config{
|
||||
ExportPath: t.TempDir(),
|
||||
ListenAddress: defaultListenAddress(defaultPort),
|
||||
RegisterEnabled: true,
|
||||
ControlPlaneURL: "http://127.0.0.1:8081",
|
||||
}, log.New(io.Discard, "", 0))
|
||||
if err == nil {
|
||||
t.Fatal("expected missing machine id to fail")
|
||||
}
|
||||
|
||||
if !strings.Contains(err.Error(), "BETTERNAS_NODE_MACHINE_ID") {
|
||||
t.Fatalf("error = %q, want missing-machine-id message", err.Error())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue