-
Notifications
You must be signed in to change notification settings - Fork 40
pass only required parameter to functions #214
pass only required parameter to functions #214
Conversation
@surajssd, thank you for the pull request! We'll ping some people to review your PR. @containscafeine, please review this. |
1 similar comment
@surajssd, thank you for the pull request! We'll ping some people to review your PR. @containscafeine, please review this. |
0d0c532
to
fe8ed8e
Compare
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.
Why?
I don't like this to be honest. I think that in a lot of cases it makes sense to pass whole app struct.
You are always passing at least two arguments that are always in the same base struct why not passing the whole struct?
@kadel because that struct has lot of other things that are not needed, so passing the function only things that it needs. why pass extra unnecessary things? What is the rationale behind passing things to function that it does not need or might manipulate? |
@kadel also with this PR it fixes #113 see code: https://github.com/kedgeproject/kedge/pull/214/files#diff-e6ad971f18906f2176a088cf3bb5b070R54 |
but you are passing arguments from the same struct. How does it make sense to break it to multiple arguments? |
What is @containscafeine's opinion on this? If he agrees with this lets merge it. I'm OK with that. |
ping @containscafeine |
pkg/encoding/fix_test.go
Outdated
) | ||
|
||
func TestFixServices(t *testing.T) { | ||
failingTest := []spec.ServiceSpecMod{ |
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'm confused, why are the tests like this? Why not put all the tests in one tests struct which has a field succeed: bool
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.
that way the testing code becomes really hard to understand with all the conditions around whether the test is expected to pass or fail, this is mere separation of successful tests and failing tests.
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.
How does it become difficult to understand, there is a field right there next to the test which says if the test is expected to pass or fail.
Also, if we separate passing and failing tests, we are sorting by test behavior not by the functionality that is being tested. One behavior will have passing and failing tests defined separately and will be very difficult to track the tests for a given behavior.
If we absolutely have to make things concise, we can have different []struct for different behavior.
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.
How does it become difficult to understand, there is a field right there next to the test which says if the test is expected to pass or fail.
The part that becomes difficult to understand is the code that runs test, for example:
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
kd, err := transformer.CreateDeployments(test.Service)
if err != nil {
if test.Succeed {
t.Errorf("Failed to create deployment from %#v\nErr: %s", test.Service, err)
}
return
}
if !test.Succeed {
t.Errorf("Expected failure, but succeeded, service: %#v\nConverted k8s Deployment: %#v", test.Service, spew.Sprint(kd))
return
}
if !reflect.DeepEqual(kd, test.K8sDeployments) {
t.Errorf("Expected: %#v\nGot: %#v\n", spew.Sprint(test.K8sDeployments), spew.Sprint(kd))
return
}
})
}
Taken from opencompose in here
If you are checking condition on test.Succeed
which is used twice, it goes out of the window when we have separated those two things.
And see the code we have here:
for _, test := range passingTests {
t.Logf("Running test: %s", test.Name)
got, err := fixServices(test.Input, appName)
if err != nil {
t.Errorf("expected to pass but failed with: %v", err)
}
if !reflect.DeepEqual(got, test.Output) {
t.Errorf("expected: %s, got: %s", prettyPrintObjects(test.Output),
prettyPrintObjects(got))
}
}
source here
No convoluted logic of test.Succeed
here. Because we know test should pass and all output should match as well.
And for failing tests we just need to see if it failed:
got, err := fixVolumeClaims(passingTest, appName)
if err != nil {
t.Errorf("expected to pass but failed with: %v", err)
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("expected: %s, got: %s", prettyPrintObjects(expected),
prettyPrintObjects(got))
}
source 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.
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.
@surajssd okay, suppose I want to test the behavior of fixing names, then I'd logically want to put the failing and passing tests together instead of splitting in different functions.
What does test the behavior of fixing names mean ?
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.
Let's not bike shed on this and get something done, I think!
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'm sorry, I'm nack on this.
Separating tests based on passing or failing makes it impossible to track the behavior being tested. We already have a structure in place, I don't understand why are we deviating from that.
I'm sorry if you feel this is bikeshedding, but this PR is deviating from the way things have been getting done for no good reason.
ping @kadel @cdrage
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.
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.
Isn't this the same discussion as in #208 (comment) ?
Can we solve this in one place?
fe8ed8e
to
fb12863
Compare
Let's move ahead on this bit and merge it unless there is huge problem. We can come back to it if need be. |
Lot of functions are being passed the entire app struct so refactoring, it to accept only what is needed.
fb12863
to
6bc8012
Compare
Lot of functions are being passed the entire app struct so refactoring, it to accept only what is needed.
Fixes #113