forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_equal.go
111 lines (103 loc) · 3.01 KB
/
container_equal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
// Package testutils contains files that are used in tests but not elsewhere and thus can
// be excluded from the final executable. Including them in a different package
// allows this to happen
package testutils
import (
"reflect"
"github.com/aws/amazon-ecs-agent/agent/api"
"github.com/aws/amazon-ecs-agent/agent/utils"
)
// ContainersEqual determines if this container is equal to another container.
// This is not exact equality, but logical equality.
// TODO: use reflection along with `equal:"unordered"` annotations on slices to
// replace this verbose code (low priority, but would be fun)
func ContainersEqual(lhs, rhs *api.Container) bool {
if lhs == rhs {
return true
}
if lhs.Name != rhs.Name || lhs.Image != rhs.Image {
return false
}
if !utils.StrSliceEqual(lhs.Command, rhs.Command) {
return false
}
if lhs.Cpu != rhs.Cpu || lhs.Memory != rhs.Memory {
return false
}
// Order doesn't matter
if !utils.SlicesDeepEqual(lhs.Links, rhs.Links) {
return false
}
if !utils.SlicesDeepEqual(lhs.VolumesFrom, rhs.VolumesFrom) {
return false
}
if !utils.SlicesDeepEqual(lhs.MountPoints, rhs.MountPoints) {
return false
}
if !utils.SlicesDeepEqual(lhs.Ports, rhs.Ports) {
return false
}
if !utils.SlicesDeepEqual(lhs.KnownPortBindings, rhs.KnownPortBindings) {
return false
}
if lhs.Essential != rhs.Essential {
return false
}
if lhs.EntryPoint == nil || rhs.EntryPoint == nil {
if lhs.EntryPoint != rhs.EntryPoint {
return false
}
// both nil
} else {
if !utils.StrSliceEqual(*lhs.EntryPoint, *rhs.EntryPoint) {
return false
}
}
if !reflect.DeepEqual(lhs.Environment, rhs.Environment) {
return false
}
if !ContainerOverridesEqual(lhs.Overrides, rhs.Overrides) {
return false
}
if lhs.DesiredStatus != rhs.DesiredStatus || lhs.KnownStatus != rhs.KnownStatus {
return false
}
if lhs.AppliedStatus != rhs.AppliedStatus {
return false
}
if lhs.KnownExitCode == nil || rhs.KnownExitCode == nil {
if lhs.KnownExitCode != nil || rhs.KnownExitCode != nil {
return false
}
} else {
if *lhs.KnownExitCode != *rhs.KnownExitCode {
return false
}
}
return true
}
// ContainerOverridesEqual determines if two container overrides are equal
func ContainerOverridesEqual(lhs, rhs api.ContainerOverrides) bool {
if lhs.Command == nil || rhs.Command == nil {
if lhs.Command != rhs.Command {
return false
}
} else {
if !utils.StrSliceEqual(*lhs.Command, *rhs.Command) {
return false
}
}
return true
}