-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests to make sure we pass through fields of corev1.Container #242
Changes from 8 commits
009ed66
5846744
d7ef70f
39e2308
5a14e6e
1ce9623
0a729b0
01c0af0
457967a
f4dfbf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ package revision | |
*/ | ||
import ( | ||
"fmt" | ||
"reflect" | ||
"regexp" | ||
"testing" | ||
"time" | ||
|
@@ -61,8 +62,25 @@ func getTestRevision() *v1alpha1.Revision { | |
}, | ||
Spec: v1alpha1.RevisionSpec{ | ||
Service: "test-service", | ||
// corev1.Container has a lot of setting. We try to pass many | ||
// of them here to verify that we pass through the settings to | ||
// derived objects. | ||
ContainerSpec: &corev1.Container{ | ||
Image: "test-image", | ||
Image: "gcr.io/repo/image", | ||
Command: []string{"echo"}, | ||
Args: []string{"hello", "world"}, | ||
WorkingDir: "/tmp", | ||
Env: []corev1.EnvVar{{ | ||
Name: "EDITOR", | ||
Value: "emacs", | ||
}}, | ||
LivenessProbe: &corev1.Probe{ | ||
TimeoutSeconds: 42, | ||
}, | ||
ReadinessProbe: &corev1.Probe{ | ||
TimeoutSeconds: 43, | ||
}, | ||
TerminationMessagePath: "/dev/null", | ||
}, | ||
}, | ||
} | ||
|
@@ -158,6 +176,16 @@ func TestCreateRevCreatesStuff(t *testing.T) { | |
func(t *testing.T) { | ||
for _, c := range p.Spec.Containers { | ||
if c.Image == rev.Spec.ContainerSpec.Image { | ||
// Make a copy and removed fields set by the controller. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: should be "remove" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. |
||
container := c.DeepCopy() | ||
container.Name = "" | ||
container.Resources = corev1.ResourceRequirements{} | ||
container.Ports = nil | ||
container.VolumeMounts = nil | ||
// Verify that all other fields match revision container spec. | ||
if !reflect.DeepEqual(container, rev.Spec.ContainerSpec) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
t.Error("pod container spec does not match revision") | ||
} | ||
return | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
cmp.Diff
here. It gives a nice message showing the differences between objects. Here's an example:https://github.com/google/elafros/blob/1b819750ff22b05ad7d6238f424a16836d17f27b/pkg/controller/route/controller_test.go#L250-L252
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.