|
| 1 | +package deprecation |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5" |
| 7 | +) |
| 8 | + |
| 9 | +func TestShouldShowAutoModeDeprecationWarning_NilConfig(t *testing.T) { |
| 10 | + cfg := &v1alpha5.ClusterConfig{ |
| 11 | + AutoModeConfig: nil, |
| 12 | + } |
| 13 | + |
| 14 | + result := shouldShowAutoModeDeprecationWarning(cfg) |
| 15 | + if !result { |
| 16 | + t.Error("Expected warning to be shown when AutoModeConfig is nil") |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +func TestShouldShowAutoModeDeprecationWarning_NilEnabled(t *testing.T) { |
| 21 | + cfg := &v1alpha5.ClusterConfig{ |
| 22 | + AutoModeConfig: &v1alpha5.AutoModeConfig{ |
| 23 | + Enabled: nil, |
| 24 | + }, |
| 25 | + } |
| 26 | + |
| 27 | + result := shouldShowAutoModeDeprecationWarning(cfg) |
| 28 | + if !result { |
| 29 | + t.Error("Expected warning to be shown when AutoModeConfig.Enabled is nil") |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +func TestShouldShowAutoModeDeprecationWarning_ExplicitlyFalse(t *testing.T) { |
| 34 | + enabled := false |
| 35 | + cfg := &v1alpha5.ClusterConfig{ |
| 36 | + AutoModeConfig: &v1alpha5.AutoModeConfig{ |
| 37 | + Enabled: &enabled, |
| 38 | + }, |
| 39 | + } |
| 40 | + |
| 41 | + result := shouldShowAutoModeDeprecationWarning(cfg) |
| 42 | + if result { |
| 43 | + t.Error("Expected no warning when AutoModeConfig.Enabled is explicitly false") |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func TestShouldShowAutoModeDeprecationWarning_ExplicitlyTrue(t *testing.T) { |
| 48 | + enabled := true |
| 49 | + cfg := &v1alpha5.ClusterConfig{ |
| 50 | + AutoModeConfig: &v1alpha5.AutoModeConfig{ |
| 51 | + Enabled: &enabled, |
| 52 | + }, |
| 53 | + } |
| 54 | + |
| 55 | + result := shouldShowAutoModeDeprecationWarning(cfg) |
| 56 | + if result { |
| 57 | + t.Error("Expected no warning when AutoModeConfig.Enabled is explicitly true") |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +func TestDefaultAutoModeDeprecationConfig(t *testing.T) { |
| 62 | + config := DefaultAutoModeDeprecationConfig() |
| 63 | + |
| 64 | + if config.Message == "" { |
| 65 | + t.Error("Expected default message to be non-empty") |
| 66 | + } |
| 67 | + |
| 68 | + if config.DocumentationURL == "" { |
| 69 | + t.Error("Expected default documentation URL to be non-empty") |
| 70 | + } |
| 71 | + |
| 72 | + if config.LogLevel != "warning" { |
| 73 | + t.Errorf("Expected default log level to be 'warning', got '%s'", config.LogLevel) |
| 74 | + } |
| 75 | + |
| 76 | + expectedMessage := "Auto Mode will be enabled by default in an upcoming release of eksctl. " + |
| 77 | + "This means managed node groups and managed networking add-ons will no longer be created by default. " + |
| 78 | + "To maintain current behavior, explicitly set 'autoModeConfig.enabled: false' in your cluster configuration." |
| 79 | + |
| 80 | + if config.Message != expectedMessage { |
| 81 | + t.Errorf("Expected default message to match specification") |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +func TestCheckAutoModeDeprecation_WithNilConfig(t *testing.T) { |
| 86 | + cfg := &v1alpha5.ClusterConfig{ |
| 87 | + AutoModeConfig: nil, |
| 88 | + } |
| 89 | + |
| 90 | + // This test verifies the function doesn't panic and executes the warning logic |
| 91 | + // We can't easily test the actual logging without mocking the logger |
| 92 | + CheckAutoModeDeprecation(cfg) |
| 93 | +} |
| 94 | + |
| 95 | +func TestCheckAutoModeDeprecation_WithExplicitlySetConfig(t *testing.T) { |
| 96 | + enabled := false |
| 97 | + cfg := &v1alpha5.ClusterConfig{ |
| 98 | + AutoModeConfig: &v1alpha5.AutoModeConfig{ |
| 99 | + Enabled: &enabled, |
| 100 | + }, |
| 101 | + } |
| 102 | + |
| 103 | + // This test verifies the function doesn't show warning when explicitly set |
| 104 | + // Since we can't easily mock the logger, we just ensure it doesn't panic |
| 105 | + CheckAutoModeDeprecation(cfg) |
| 106 | +} |
| 107 | + |
| 108 | +func TestCheckAutoModeDeprecationWithConfig_CustomConfig(t *testing.T) { |
| 109 | + cfg := &v1alpha5.ClusterConfig{ |
| 110 | + AutoModeConfig: nil, |
| 111 | + } |
| 112 | + |
| 113 | + customConfig := &AutoModeDeprecationConfig{ |
| 114 | + Message: "Custom test message", |
| 115 | + DocumentationURL: "https://example.com", |
| 116 | + LogLevel: "info", |
| 117 | + } |
| 118 | + |
| 119 | + // This test verifies the function accepts custom configuration |
| 120 | + CheckAutoModeDeprecationWithConfig(cfg, customConfig) |
| 121 | +} |
0 commit comments