@@ -70,3 +70,64 @@ machine:
7070 t .Errorf ("expected 0 templates, got %d: %v" , len (templates ), templates )
7171 }
7272}
73+
74+ func TestProcessModelineAndUpdateGlobals_InvalidModeline (t * testing.T ) {
75+ origNodes := GlobalArgs .Nodes
76+ origEndpoints := GlobalArgs .Endpoints
77+ defer func () {
78+ GlobalArgs .Nodes = origNodes
79+ GlobalArgs .Endpoints = origEndpoints
80+ }()
81+
82+ tmpDir := t .TempDir ()
83+ configFile := filepath .Join (tmpDir , "node0.yaml" )
84+ content := `# talm: this is not valid modeline syntax
85+ machine:
86+ type: controlplane
87+ `
88+ if err := os .WriteFile (configFile , []byte (content ), 0o644 ); err != nil {
89+ t .Fatalf ("failed to write temp file: %v" , err )
90+ }
91+
92+ GlobalArgs .Nodes = []string {}
93+ GlobalArgs .Endpoints = []string {}
94+
95+ templates , err := processModelineAndUpdateGlobals (configFile , false , false , true )
96+ if err == nil {
97+ t .Fatal ("expected error for invalid modeline, got nil" )
98+ }
99+ if templates != nil {
100+ t .Errorf ("expected nil templates on error, got %v" , templates )
101+ }
102+ }
103+
104+ func TestProcessModelineAndUpdateGlobals_EmptyNodesError (t * testing.T ) {
105+ origNodes := GlobalArgs .Nodes
106+ origEndpoints := GlobalArgs .Endpoints
107+ defer func () {
108+ GlobalArgs .Nodes = origNodes
109+ GlobalArgs .Endpoints = origEndpoints
110+ }()
111+
112+ tmpDir := t .TempDir ()
113+ configFile := filepath .Join (tmpDir , "node0.yaml" )
114+ // Valid modeline but with empty nodes
115+ content := `# talm: nodes=[], endpoints=["10.0.0.1"], templates=["templates/controlplane.yaml"]
116+ machine:
117+ type: controlplane
118+ `
119+ if err := os .WriteFile (configFile , []byte (content ), 0o644 ); err != nil {
120+ t .Fatalf ("failed to write temp file: %v" , err )
121+ }
122+
123+ GlobalArgs .Nodes = []string {}
124+ GlobalArgs .Endpoints = []string {}
125+
126+ templates , err := processModelineAndUpdateGlobals (configFile , false , false , true )
127+ if err == nil {
128+ t .Fatal ("expected error for empty nodes, got nil" )
129+ }
130+ if templates != nil {
131+ t .Errorf ("expected nil templates on error, got %v" , templates )
132+ }
133+ }
0 commit comments