|
| 1 | +// (c) Copyright 2021 Hewlett Packard Enterprise Development LP |
| 2 | + |
| 3 | +package util |
| 4 | + |
| 5 | +import "testing" |
| 6 | + |
| 7 | +func TestGetMacAddressHostNameMD5Hash(t *testing.T) { |
| 8 | + testCases := []struct { |
| 9 | + name string |
| 10 | + macAddress1 string |
| 11 | + hostName1 string |
| 12 | + macAddress2 string |
| 13 | + hostName2 string |
| 14 | + expectSame bool |
| 15 | + }{ |
| 16 | + { |
| 17 | + name: "same mac address but different hostname", |
| 18 | + macAddress1: "0a58a9fe0001", |
| 19 | + macAddress2: "0a58a9fe0001", |
| 20 | + hostName1: "host-dev", |
| 21 | + hostName2: "host-prod", |
| 22 | + expectSame: false, |
| 23 | + }, |
| 24 | + { |
| 25 | + name: "same hostname but different mac address", |
| 26 | + macAddress1: "0a58a9fe0001", |
| 27 | + macAddress2: "0a58a9fe0002", |
| 28 | + hostName1: "host-dev", |
| 29 | + hostName2: "host-dev", |
| 30 | + expectSame: false, |
| 31 | + }, |
| 32 | + { |
| 33 | + name: "same hostname and same mac address", |
| 34 | + macAddress1: "0a58a9fe0001", |
| 35 | + macAddress2: "0a58a9fe0001", |
| 36 | + hostName1: "host-dev", |
| 37 | + hostName2: "host-dev", |
| 38 | + expectSame: true, |
| 39 | + }, |
| 40 | + } |
| 41 | + |
| 42 | + for _, tc := range testCases { |
| 43 | + t.Run(tc.name, func(t *testing.T) { |
| 44 | + idStr1 := GetMD5HashOfTwoStrings(tc.macAddress1, tc.hostName1) |
| 45 | + idStr2 := GetMD5HashOfTwoStrings(tc.macAddress2, tc.hostName2) |
| 46 | + if idStr1 == idStr2 && !tc.expectSame { |
| 47 | + t.Fatalf("Expected %s to be different from %s for test %s", idStr1, idStr2, tc.name) |
| 48 | + } |
| 49 | + if idStr1 != idStr2 && tc.expectSame { |
| 50 | + t.Fatalf("Expected %s to be same as %s for test %s", idStr1, idStr2, tc.name) |
| 51 | + } |
| 52 | + }) |
| 53 | + } |
| 54 | +} |
0 commit comments