-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Move clusterdeployer_test.go into clusterdeployer package #439
Move clusterdeployer_test.go into clusterdeployer package #439
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
CLA signed |
/ok-to-test |
@ashish-amarnath - first of all, thank you for sending this PR, and especially for writing tests and working to help improve our test coverage. In June during the weekly working group meeting we discussed removing machine role from the machine spec (notes). As I result, I opened #338 and created #405 (which hasn't merged yet, but should merge soon). That PR removes the two functions that you wrote tests for in this PR. |
@roberthbailey Thanks for the explanation. I will remove the tests that I added. But I would like to preserve the changes to the Makefile and also the package name for the |
af475be
to
3ace788
Compare
3ace788
to
8c8df76
Compare
@ashish-amarnath - the package rename looks good. As for the makefile, I'm not sure why you'd want the makefile at the root level to only run clusterctl tests / coverage when there is lots of other code in pkg and cmd. https://github.com/kubernetes-sigs/cluster-api/blob/master/scripts/ci-test.sh runs all unit and integration tests in the repo. Maybe we could move that into the makefile (and have the script just call make If we really want make targets that are specific to the clusterctl directory, what about adding a makefile to that dir? |
+1 to @roberthbailey's point about only testing clusterctl in the root level. We should test everything (minus vendor) in the root. |
@roberthbailey I didn't know the existence of that script. Thanks for pointing that out :) Now that I know of the test script, which runs successfully, I will not open that issue and will also undo the changes to the makefile. |
Move clusterdeployer_test into clusterdeployer package Signed-off-by: Ashish Amarnath <ashish.amarnath@gmail.com>
8c8df76
to
c33a09b
Compare
Also, just realized that we can use the tests that I wrote for |
If you'd like a make target instead of the script, the makefile successfully runs go test at the root level so you could use that to help figure out why your invocation was failing. Adding test coverage for the new methods would be greatly appreciated. |
* remove unused PHONY make targets
I take back my initial comment that the script runs successfully.
The reason, as the error suggests, I don't have etcd on my laptop. So this would be an expected failure. Am I missing anything in my dev-setup to get this to pass? |
It looks like you are missing having etcd in your path. :) I think most other folks have stuck in there in the past as they were working on other parts of Kubernetes that required it for unit/integration testing so no one noticed that it was required. Could you file an issue and/or send a documentation update to make it part of the developer getting started instructions? |
{ | ||
name: "success_1_master_multiple_nodes", | ||
inputMachines: generateValidExtractMasterMachineInput(singleMasterName, multipleNodeNames), | ||
expectedMasters: generateMasterNode("test-master"), |
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.
nit: pass singleMasterName here instead of the raw string.
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 had missed that. Thanks!
actualMasters, actualNodes, actualError := extractMasterMachine(tc.inputMachines) | ||
|
||
if tc.expectedError == nil && actualError != nil { | ||
t.Fatalf("Expected error=[nil], Actual error=[%v]", actualError) |
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.
Your test strings are backwards according to the go style (see https://github.com/golang/go/wiki/CodeReviewComments#useful-test-failures)
Something like t.Fatalf("extractMasterMachine(%q) = %q; want %q", tc.inputMachines, actualError, tc.expectedError)
would be more along the lines of the style recommendation.
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.
Thank you for that link!
master := &clusterv1.Machine{} | ||
master.Name = "test-master" | ||
master.Name = name |
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.
It was this way before but I don't understand why these parameters are set here rather than when creating the Machine on the above line. Is there a reason we can't write
return &clusterv1.Machine{
Name: name,
Spec: clusterv1.MachineSpec{
Versions: clusterv1.MachineVersionInfo{
ControlPlane: "1.10.1",
},
},
}
(or the variation of that which compiles)?
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.
No reason. I was just following the way this was before. Now I've moved the setting of fields into the initializer.
func generateTestMasterMachine(masterNames []string) []*clusterv1.Machine { | ||
var masters []*clusterv1.Machine | ||
for _, mn := range masterNames { | ||
m := generateMasterNode(mn) |
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.
combine with the next line: masters = append(masters, generateMasterNode(mn))
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.
func generateTestNodeMachines(nodeNames []string) []*clusterv1.Machine { | ||
var nodes []*clusterv1.Machine | ||
for _, nn := range nodeNames { | ||
n := &clusterv1.Machine{} |
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.
nodes = append(nodes, &clusterv1.Machine{Name: nn})
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
masters := generateTestMasterMachine(masterNames) | ||
nodes := generateTestNodeMachines(nodeNames) | ||
|
||
var inputMachines []*clusterv1.Machine |
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.
return append(masters, nodes...)
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
} | ||
|
||
func generateValidExtractMasterMachineInput(masterName string, nodeNames []string) []*clusterv1.Machine { | ||
masters := generateMasterNode(masterName) |
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.
Make masters an array (to match the plural name:
masters = []*clusterv1.Machine{generateMasterNode(masterName)}
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
masters := generateMasterNode(masterName) | ||
nodes := generateTestNodeMachines(nodeNames) | ||
|
||
var inputMachines []*clusterv1.Machine |
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.
return append(masters, nodes...)
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.
} | ||
|
||
func generateMachines() []*clusterv1.Machine { | ||
master := generateMasterNode("test-master") | ||
node := &clusterv1.Machine{} |
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.
node := &clusterv1.Machine{Name: "test.Node"}
} | ||
|
||
func generateMachines() []*clusterv1.Machine { | ||
master := generateMasterNode("test-master") | ||
node := &clusterv1.Machine{} | ||
node.Name = "test.Node" |
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.
Do you have any idea why the syntax for master & node names is different (dash vs. dot)?
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.
No, I don't. It seems odd though. I am going to use the dash syntax.
* follow style guidelines for test failure messages * set fields in test data using initializers * refactor to simplify test data generation
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ashish-amarnath, roberthbailey The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@roberthbailey Thank you! |
…se-tag Match release tag script
Signed-off-by: Ashish Amarnath ashish.amarnath@gmail.com
What this PR does / why we need it:
This PR makes
clusterdeployer.go
more testable by movingclusterdeployer_test.go
into the same package asclusterdeployer.go
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer:
No image versions being changed in the PR.
Release note: