|
| 1 | +// © Broadcom. All Rights Reserved. |
| 2 | +// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. |
| 3 | +// SPDX-License-Identifier: MPL-2.0 |
| 4 | + |
| 5 | +package common |
| 6 | + |
| 7 | +import ( |
| 8 | + "strings" |
| 9 | + "testing" |
| 10 | + "time" |
| 11 | +) |
| 12 | + |
| 13 | +func TestWaitIpConfig_Prepare_defaults(t *testing.T) { |
| 14 | + c := &WaitIpConfig{} |
| 15 | + errs := c.Prepare() |
| 16 | + if len(errs) > 0 { |
| 17 | + t.Fatalf("unexpected errors: %v", errs) |
| 18 | + } |
| 19 | + if c.WaitTimeout != 30*time.Minute { |
| 20 | + t.Fatalf("expected default wait timeout 30m, got %v", c.WaitTimeout) |
| 21 | + } |
| 22 | + if c.WaitAddress == nil || *c.WaitAddress != "0.0.0.0/0" { |
| 23 | + t.Fatalf("expected default ip_wait_address 0.0.0.0/0, got %v", c.WaitAddress) |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func TestWaitIpConfig_ValidateDisableIpWait(t *testing.T) { |
| 28 | + t.Run("disabled by default", func(t *testing.T) { |
| 29 | + c := &WaitIpConfig{} |
| 30 | + warnings, errs := c.ValidateDisableIpWait("") |
| 31 | + if len(warnings) > 0 || len(errs) > 0 { |
| 32 | + t.Fatalf("expected no warnings or errors, got warnings=%v errs=%v", warnings, errs) |
| 33 | + } |
| 34 | + }) |
| 35 | + |
| 36 | + t.Run("requires communicator host", func(t *testing.T) { |
| 37 | + c := &WaitIpConfig{DisableIpWait: true} |
| 38 | + warnings, errs := c.ValidateDisableIpWait("") |
| 39 | + if len(errs) != 1 { |
| 40 | + t.Fatalf("expected one error, got %v", errs) |
| 41 | + } |
| 42 | + if len(warnings) != 1 { |
| 43 | + t.Fatalf("expected one warning, got %v", warnings) |
| 44 | + } |
| 45 | + }) |
| 46 | + |
| 47 | + t.Run("ok with ssh host", func(t *testing.T) { |
| 48 | + c := &WaitIpConfig{DisableIpWait: true} |
| 49 | + warnings, errs := c.ValidateDisableIpWait("192.168.1.10") |
| 50 | + if len(errs) > 0 { |
| 51 | + t.Fatalf("unexpected errors: %v", errs) |
| 52 | + } |
| 53 | + if len(warnings) != 1 || !strings.Contains(warnings[0], "disable_ip_wait") { |
| 54 | + t.Fatalf("expected disable_ip_wait warning, got %v", warnings) |
| 55 | + } |
| 56 | + }) |
| 57 | +} |
0 commit comments