CollectDifferencesFromMaps returns a map of the differences (as slice of strings) of the values of two given maps. Map result values are added when a key is present just in one of the input maps, or if the values are different given the same key
(p1 map[string]string, p2 map[string]string)
| 23 | // Map result values are added when a key is present just in one of the input maps, or if the values are different |
| 24 | // given the same key |
| 25 | func CollectDifferencesFromMaps(p1 map[string]string, p2 map[string]string) map[string][]string { |
| 26 | diff := make(map[string][]string) |
| 27 | totalKeys := make(map[string]bool) |
| 28 | for k := range p1 { |
| 29 | totalKeys[k] = true |
| 30 | } |
| 31 | for k := range p2 { |
| 32 | totalKeys[k] = true |
| 33 | } |
| 34 | for k := range totalKeys { |
| 35 | v1, ok1 := p1[k] |
| 36 | v2, ok2 := p2[k] |
| 37 | if ok1 && ok2 && v1 == v2 { |
| 38 | continue |
| 39 | } |
| 40 | diff[k] = []string{v1, v2} |
| 41 | } |
| 42 | if len(diff) > 0 { |
| 43 | return diff |
| 44 | } |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | // IsMapSubset returns true if mapSubset is a subset of mapSet otherwise false |
| 49 | func IsMapSubset(mapSet map[string]string, mapSubset map[string]string) bool { |
no outgoing calls
no test coverage detected