|
| 1 | +package rancher2 |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + rkev1 "github.com/rancher/rancher/pkg/apis/rke.cattle.io/v1" |
| 8 | +) |
| 9 | + |
| 10 | +var ( |
| 11 | + testClusterV2RKEConfigETCDSnapshotRestoreConf *rkev1.ETCDSnapshotRestore |
| 12 | + testClusterV2RKEConfigETCDSnapshotRestoreInterface []interface{} |
| 13 | +) |
| 14 | + |
| 15 | +func init() { |
| 16 | + testClusterV2RKEConfigETCDSnapshotRestoreConf = &rkev1.ETCDSnapshotRestore{ |
| 17 | + Name: "SnapshotTestName", |
| 18 | + Generation: 1, |
| 19 | + RestoreRKEConfig: "all", |
| 20 | + } |
| 21 | + |
| 22 | + testClusterV2RKEConfigETCDSnapshotRestoreInterface = []interface{}{ |
| 23 | + map[string]interface{}{ |
| 24 | + "name": "SnapshotTestName", |
| 25 | + "generation": 1, |
| 26 | + "restore_rke_config": "all", |
| 27 | + }, |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestFlattenClusterV2RKEConfigETCDSnapshotRestore(t *testing.T) { |
| 32 | + cases := []struct { |
| 33 | + Input *rkev1.ETCDSnapshotRestore |
| 34 | + ExpectedOutput []interface{} |
| 35 | + }{ |
| 36 | + { |
| 37 | + testClusterV2RKEConfigETCDSnapshotRestoreConf, |
| 38 | + testClusterV2RKEConfigETCDSnapshotRestoreInterface, |
| 39 | + }, |
| 40 | + } |
| 41 | + |
| 42 | + for _, tc := range cases { |
| 43 | + output := flattenClusterV2RKEConfigETCDSnapshotRestore(tc.Input) |
| 44 | + if !reflect.DeepEqual(output, tc.ExpectedOutput) { |
| 45 | + t.Fatalf("Unexpected output from flattener.\nExpected: %#v\nGiven: %#v", |
| 46 | + tc.ExpectedOutput, output) |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +func TestExpandClusterV2RKEConfigETCDSnapshotRestore(t *testing.T) { |
| 52 | + |
| 53 | + cases := []struct { |
| 54 | + Input []interface{} |
| 55 | + ExpectedOutput *rkev1.ETCDSnapshotRestore |
| 56 | + }{ |
| 57 | + { |
| 58 | + testClusterV2RKEConfigETCDSnapshotRestoreInterface, |
| 59 | + testClusterV2RKEConfigETCDSnapshotRestoreConf, |
| 60 | + }, |
| 61 | + } |
| 62 | + |
| 63 | + for _, tc := range cases { |
| 64 | + output := expandClusterV2RKEConfigETCDSnapshotRestore(tc.Input) |
| 65 | + if !reflect.DeepEqual(output, tc.ExpectedOutput) { |
| 66 | + t.Fatalf("Unexpected output from expander.\nExpected: %#v\nGiven: %#v", |
| 67 | + tc.ExpectedOutput, output) |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments