|
| 1 | +package dsf_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf" |
| 7 | +) |
| 8 | + |
| 9 | +func TestDiffSuppress_IPAMIP(t *testing.T) { |
| 10 | + tests := []struct { |
| 11 | + name string |
| 12 | + oldValue string |
| 13 | + newValue string |
| 14 | + want bool |
| 15 | + }{ |
| 16 | + { |
| 17 | + name: "IP == IP", |
| 18 | + oldValue: "172.16.32.7", |
| 19 | + newValue: "172.16.32.7", |
| 20 | + want: true, |
| 21 | + }, |
| 22 | + { |
| 23 | + name: "IP == IP/CIDR same host", |
| 24 | + oldValue: "172.16.32.7/22", |
| 25 | + newValue: "172.16.32.7", |
| 26 | + want: true, |
| 27 | + }, |
| 28 | + { |
| 29 | + name: "IP/CIDR == IP same host (reversed)", |
| 30 | + oldValue: "172.16.32.7", |
| 31 | + newValue: "172.16.32.7/22", |
| 32 | + want: true, |
| 33 | + }, |
| 34 | + { |
| 35 | + name: "Different host within same CIDR is NOT suppressed", |
| 36 | + oldValue: "172.16.32.7/22", |
| 37 | + newValue: "172.16.32.8", |
| 38 | + want: false, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "Different host (plain IPs) is NOT suppressed", |
| 42 | + oldValue: "172.16.32.7", |
| 43 | + newValue: "172.16.32.8", |
| 44 | + want: false, |
| 45 | + }, |
| 46 | + { |
| 47 | + name: "Equal but with /32 single-host CIDR", |
| 48 | + oldValue: "10.0.0.1/32", |
| 49 | + newValue: "10.0.0.1", |
| 50 | + want: true, |
| 51 | + }, |
| 52 | + { |
| 53 | + name: "Broader CIDR vs network address should NOT suppress", |
| 54 | + oldValue: "10.0.0.1/24", |
| 55 | + newValue: "10.0.0.0", |
| 56 | + want: false, |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "Invalid old value -> not suppressed", |
| 60 | + oldValue: "not-an-ip", |
| 61 | + newValue: "10.0.0.1", |
| 62 | + want: false, |
| 63 | + }, |
| 64 | + { |
| 65 | + name: "Invalid new value -> not suppressed", |
| 66 | + oldValue: "10.0.0.1", |
| 67 | + newValue: "bad/32", |
| 68 | + want: false, |
| 69 | + }, |
| 70 | + { |
| 71 | + name: "Both invalid -> not suppressed", |
| 72 | + oldValue: "nope", |
| 73 | + newValue: "nope2", |
| 74 | + want: false, |
| 75 | + }, |
| 76 | + } |
| 77 | + |
| 78 | + for _, tt := range tests { |
| 79 | + t.Run(tt.name, func(t *testing.T) { |
| 80 | + got := dsf.DiffSuppressFuncStandaloneIPandCIDR("", tt.oldValue, tt.newValue, nil) |
| 81 | + if got != tt.want { |
| 82 | + t.Fatalf("diffSuppress(%q, %q) = %v, want %v", tt.oldValue, tt.newValue, got, tt.want) |
| 83 | + } |
| 84 | + }) |
| 85 | + } |
| 86 | +} |
0 commit comments