-
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
Conversation
Even though ContainerSpec accepts all fields of core/v1/Container, the controller will silently overwrite some fields, like Name, Resources, Ports, and VolumeMounts. This will cause confusions if the users expect their settings to be effective. This change disallows specifying those fields to avoid the confusions.
@grantr take a look? thanks |
Oops, missed this one @tcnghia, 👀 now |
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.
Thanks @tcnghia! Always good to see tests improvements. I'd like to standardize on cmp.Diff
in tests instead of reflect.DeepEqual
.
@@ -147,6 +167,10 @@ func TestCreateConfigurationsCreatesRevision(t *testing.T) { | |||
t.Errorf("rev service was not %s", config.Spec.Template.Spec.Service) | |||
} | |||
|
|||
if !reflect.DeepEqual(rev.Spec, config.Spec.Template.Spec) { |
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:
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.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Use cmp.Diff
here too.
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
@@ -158,6 +171,12 @@ func TestCreateRevCreatesStuff(t *testing.T) { | |||
func(t *testing.T) { | |||
for _, c := range p.Spec.Containers { | |||
if c.Image == rev.Spec.ContainerSpec.Image { | |||
// Ignoring fields set by Elafros controller. | |||
ignored := cmpopts.IgnoreFields(corev1.Container{}, "Name", "Ports", "Resources", "VolumeMounts") |
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.
I like the change to using IgnoreFields
here!
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.
thanks about cmp.Diff suggestion 👍
I am pretty new to Go, so would love to receive lots of recommendations like these.
Fixes #176