- Update edge node registry with snapshot tracking - Fix mapper and store tests for registry changes - Update transport server integration tests - Add config support for new edge settings - Sync roadmap with current phase progress - Archive completed task groups
166 lines
4.3 KiB
Go
166 lines
4.3 KiB
Go
package node_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
edgenode "iop/apps/edge/internal/node"
|
|
"iop/packages/go/config"
|
|
)
|
|
|
|
func TestLoadFromConfig_Success(t *testing.T) {
|
|
store, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{Alias: "beta", Token: "token-beta"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("load from config: %v", err)
|
|
}
|
|
|
|
rec, ok := store.FindByToken("token-beta")
|
|
if !ok {
|
|
t.Fatal("expected record for token-beta")
|
|
}
|
|
if rec.Alias != "beta" {
|
|
t.Fatalf("expected alias %q, got %q", "beta", rec.Alias)
|
|
}
|
|
if rec.ID == "" {
|
|
t.Fatal("expected non-empty ID")
|
|
}
|
|
|
|
if _, ok := store.FindByToken("missing"); ok {
|
|
t.Fatal("expected missing token lookup to fail")
|
|
}
|
|
}
|
|
|
|
func TestLoadFromConfig_DuplicateToken(t *testing.T) {
|
|
_, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{Alias: "alpha", Token: "token"},
|
|
{Alias: "beta", Token: "token"},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("expected duplicate token error")
|
|
}
|
|
}
|
|
|
|
func TestLoadFromConfig_DuplicateAlias(t *testing.T) {
|
|
_, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{Alias: "alpha", Token: "token-alpha"},
|
|
{Alias: "alpha", Token: "token-beta"},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("expected duplicate alias error")
|
|
}
|
|
}
|
|
|
|
func TestLoadFromConfig_EmptyToken(t *testing.T) {
|
|
_, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{Alias: "alpha"},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("expected empty token error")
|
|
}
|
|
}
|
|
|
|
func TestLoadFromConfig_ExplicitID(t *testing.T) {
|
|
store, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{ID: "my-custom-id", Alias: "alpha", Token: "token-alpha"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("load from config: %v", err)
|
|
}
|
|
|
|
rec, ok := store.FindByToken("token-alpha")
|
|
if !ok {
|
|
t.Fatal("expected record for token-alpha")
|
|
}
|
|
if rec.ID != "my-custom-id" {
|
|
t.Fatalf("expected id %q, got %q", "my-custom-id", rec.ID)
|
|
}
|
|
}
|
|
|
|
func TestLoadFromConfig_AutoID(t *testing.T) {
|
|
store, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{Alias: "alpha", Token: "token-alpha"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("load from config: %v", err)
|
|
}
|
|
|
|
rec, ok := store.FindByToken("token-alpha")
|
|
if !ok {
|
|
t.Fatal("expected record for token-alpha")
|
|
}
|
|
if rec.ID == "" {
|
|
t.Fatal("expected auto-generated non-empty ID")
|
|
}
|
|
if rec.ID == "node-alpha" {
|
|
t.Fatal("expected UUID, not alias-derived ID")
|
|
}
|
|
}
|
|
|
|
func TestLoadFromConfig_DuplicateID(t *testing.T) {
|
|
_, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{ID: "node-dup", Alias: "alpha", Token: "token-alpha"},
|
|
{ID: "node-dup", Alias: "beta", Token: "token-beta"},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("expected duplicate id error")
|
|
}
|
|
}
|
|
|
|
func TestLoadFromConfigAgentKind(t *testing.T) {
|
|
store, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{Alias: "agent", Token: "token-agent", AgentKind: config.AgentKindOTOAgent},
|
|
{Alias: "plain", Token: "token-plain"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("load from config: %v", err)
|
|
}
|
|
|
|
agentRec, ok := store.FindByToken("token-agent")
|
|
if !ok {
|
|
t.Fatal("expected record for token-agent")
|
|
}
|
|
if agentRec.AgentKind != config.AgentKindOTOAgent {
|
|
t.Fatalf("expected agent_kind=%q, got %q", config.AgentKindOTOAgent, agentRec.AgentKind)
|
|
}
|
|
|
|
plainRec, ok := store.FindByToken("token-plain")
|
|
if !ok {
|
|
t.Fatal("expected record for token-plain")
|
|
}
|
|
if plainRec.AgentKind != config.AgentKindGenericNode {
|
|
t.Fatalf("expected default agent_kind=%q, got %q", config.AgentKindGenericNode, plainRec.AgentKind)
|
|
}
|
|
}
|
|
|
|
func TestLoadFromConfig_DuplicateTokenWithAgentKind(t *testing.T) {
|
|
_, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{Alias: "alpha", Token: "token", AgentKind: config.AgentKindOTOAgent},
|
|
{Alias: "beta", Token: "token", AgentKind: config.AgentKindGenericNode},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("expected duplicate token error regardless of agent kind")
|
|
}
|
|
}
|
|
|
|
func TestLoadFromConfig_AutoIDUnique(t *testing.T) {
|
|
store, err := edgenode.LoadFromConfig([]config.NodeDefinition{
|
|
{Alias: "alpha", Token: "token-alpha"},
|
|
{Alias: "beta", Token: "token-beta"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("load from config: %v", err)
|
|
}
|
|
|
|
recA, ok := store.FindByToken("token-alpha")
|
|
if !ok {
|
|
t.Fatal("expected record for token-alpha")
|
|
}
|
|
recB, ok := store.FindByToken("token-beta")
|
|
if !ok {
|
|
t.Fatal("expected record for token-beta")
|
|
}
|
|
if recA.ID == recB.ID {
|
|
t.Fatalf("expected unique IDs, both are %q", recA.ID)
|
|
}
|
|
}
|