@@ -26,6 +26,7 @@ import (
2626 cli "github.com/urfave/cli/v3"
2727
2828 "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container"
29+ "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/toml"
2930)
3031
3132// TestContainerdConfigLifecycle tests the complete Setup->Cleanup lifecycle for both v1 and v2 configs.
@@ -318,7 +319,10 @@ func TestContainerdConfigLifecycle(t *testing.T) {
318319 actual , err := os .ReadFile (configPath )
319320 require .NoError (t , err )
320321
321- t .Logf ("=== CONFIG AFTER SETUP ===\n %s\n === END CONFIG ===" , string (actual ))
322+ t .Logf ("=== CONFIG AFTER SETUP (v2: top-level config does not exist) ===" )
323+ t .Logf ("File size: %d bytes" , len (actual ))
324+ t .Logf ("Content:\n %s" , string (actual ))
325+ t .Logf ("=== END CONFIG ===" )
322326
323327 expected := `version = 2
324328
@@ -362,20 +366,53 @@ func TestContainerdConfigLifecycle(t *testing.T) {
362366 },
363367 assertCleanupPostConditions : func (t * testing.T , testRoot string ) error {
364368 configPath := filepath .Join (testRoot , "etc/containerd/config.toml" )
365- // On cleanup, config may be deleted or may contain minimal config
366- _ , err := os .Stat (configPath )
369+
370+ t .Logf ("=== CLEANUP POST-CONDITIONS CHECK (v2: top-level config does not exist) ===" )
371+
372+ // Check file existence
373+ fileInfo , err := os .Stat (configPath )
367374 if os .IsNotExist (err ) {
368- // File was deleted, which is fine
369- t .Logf ("=== CONFIG AFTER CLEANUP === \n File was deleted \n === END CONFIG ===" )
375+ t . Logf ( "Result: File was deleted (expected on macOS)" )
376+ t .Logf ("=== END CLEANUP CHECK ===" )
370377 return nil
371378 }
372- // If file exists, it should not contain nvidia runtimes
379+
380+ // File exists - analyze it
381+ t .Logf ("Result: File still exists (size: %d bytes)" , fileInfo .Size ())
382+
373383 actual , err := os .ReadFile (configPath )
374384 require .NoError (t , err )
375385 actualStr := string (actual )
376386
377- t .Logf ("=== CONFIG AFTER CLEANUP ===\n %s\n === END CONFIG ===" , actualStr )
387+ t .Logf ("Content after cleanup:\n %s" , actualStr )
388+ t .Logf ("File analysis:" )
389+ t .Logf (" - Size: %d bytes" , len (actualStr ))
390+ t .Logf (" - Lines: %d" , strings .Count (actualStr , "\n " ))
391+ t .Logf (" - Is empty: %v" , len (actualStr ) == 0 )
392+
393+ // Analyze structure
394+ if strings .Contains (actualStr , "plugins" ) {
395+ t .Logf (" - Contains 'plugins' section" )
396+ }
397+ if strings .Contains (actualStr , "version" ) {
398+ t .Logf (" - Contains 'version' field" )
399+ }
400+ if strings .Contains (actualStr , "runtime" ) {
401+ t .Logf (" - Contains 'runtime' text somewhere" )
402+ }
403+
404+ // Count top-level sections
405+ tree , err := toml .LoadFile (configPath )
406+ if err == nil {
407+ t .Logf (" - Number of top-level keys: %d" , len (tree .Keys ()))
408+ for _ , key := range tree .Keys () {
409+ t .Logf (" - Top-level key: %s" , key )
410+ }
411+ }
412+
413+ t .Logf ("=== END CLEANUP CHECK ===" )
378414
415+ // Actual assertions
379416 require .NotContains (t , actualStr , "nvidia" )
380417 require .NotContains (t , actualStr , "nvidia-cdi" )
381418 require .NotContains (t , actualStr , "nvidia-legacy" )
@@ -467,11 +504,30 @@ func TestContainerdConfigLifecycle(t *testing.T) {
467504 },
468505 assertCleanupPostConditions : func (t * testing.T , testRoot string ) error {
469506 configPath := filepath .Join (testRoot , "etc/containerd/config.toml" )
507+
508+ t .Logf ("=== CLEANUP POST-CONDITIONS CHECK (v2: existing config without nvidia runtime) ===" )
509+
470510 require .FileExists (t , configPath )
471511
472512 actual , err := os .ReadFile (configPath )
473513 require .NoError (t , err )
474514
515+ t .Logf ("Content after cleanup:\n %s" , string (actual ))
516+ t .Logf ("File analysis:" )
517+ t .Logf (" - Size: %d bytes" , len (actual ))
518+ t .Logf (" - Lines: %d" , strings .Count (string (actual ), "\n " ))
519+
520+ // Analyze structure
521+ tree , err := toml .LoadFile (configPath )
522+ if err == nil {
523+ t .Logf (" - Number of top-level keys: %d" , len (tree .Keys ()))
524+ for _ , key := range tree .Keys () {
525+ t .Logf (" - Top-level key: %s" , key )
526+ }
527+ }
528+
529+ t .Logf ("=== END CLEANUP CHECK ===" )
530+
475531 expected := `version = 2
476532
477533[plugins]
@@ -835,6 +891,20 @@ version = 2
835891 require .NoError (t , tc .assertSetupPostConditions (t , testRoot ))
836892 }
837893
894+ // Debug: Log config state before cleanup
895+ configPath := filepath .Join (testRoot , "etc/containerd/config.toml" )
896+ if _ , err := os .Stat (configPath ); err == nil {
897+ content , _ := os .ReadFile (configPath )
898+ t .Logf ("=== CONFIG BEFORE CLEANUP ===" )
899+ t .Logf ("Size: %d bytes" , len (content ))
900+ previewLen := 200
901+ if len (content ) < previewLen {
902+ previewLen = len (content )
903+ }
904+ t .Logf ("First %d chars: %s" , previewLen , string (content [:previewLen ]))
905+ t .Logf ("=== END PRE-CLEANUP ===" )
906+ }
907+
838908 err = Cleanup (c , & tc .containerOptions , & tc .options )
839909 require .EqualValues (t , tc .expectedCleanupError , err )
840910
0 commit comments