-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63991 from neolit123/test-upgrade-diff
Automatic merge from submit-queue (batch tested with PRs 62025, 63851, 64077, 63967, 63991). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add unit tests to `kubeadm upgrade diff` and small improvements **What this PR does / why we need it**: has a couple of commits: I. ``` 1) Store the io.Writer and pass it to sub-commands in upgrade.go 2) Check if the manifest path is an empty string in diff.go:runDiff() 3) Use the io.Writer that upgrade.go defines instead of writing to os.Stdout directly. ``` II. ``` Add the file diff_test.go, which has a single test: TestRunDiff The test covers most error cases for the runDiff() function, and also performs a valid diff. ``` **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 kubernetes/kubeadm#826 **Special notes for your reviewer**: @liztio @luxas **Release note**: ```release-note NONE ```
- Loading branch information
Showing
6 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License 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 upgrade | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
) | ||
|
||
const ( | ||
testUpgradeDiffConfig = `testdata/diff_master_config.yaml` | ||
testUpgradeDiffManifest = `testdata/diff_dummy_manifest.yaml` | ||
) | ||
|
||
func TestRunDiff(t *testing.T) { | ||
parentFlags := &cmdUpgradeFlags{ | ||
cfgPath: "", | ||
out: ioutil.Discard, | ||
} | ||
flags := &diffFlags{ | ||
parent: parentFlags, | ||
} | ||
|
||
testCases := []struct { | ||
name string | ||
args []string | ||
setManifestPath bool | ||
manifestPath string | ||
cfgPath string | ||
expectedError bool | ||
}{ | ||
{ | ||
name: "valid: run diff on valid manifest path", | ||
cfgPath: testUpgradeDiffConfig, | ||
setManifestPath: true, | ||
manifestPath: testUpgradeDiffManifest, | ||
expectedError: false, | ||
}, | ||
{ | ||
name: "invalid: missing config file", | ||
cfgPath: "missing-path-to-a-config", | ||
expectedError: true, | ||
}, | ||
{ | ||
name: "invalid: valid config but empty manifest path", | ||
cfgPath: testUpgradeDiffConfig, | ||
setManifestPath: true, | ||
manifestPath: "", | ||
expectedError: true, | ||
}, | ||
{ | ||
name: "invalid: valid config but bad manifest path", | ||
cfgPath: testUpgradeDiffConfig, | ||
setManifestPath: true, | ||
manifestPath: "bad-path", | ||
expectedError: true, | ||
}, | ||
{ | ||
name: "invalid: badly formatted version as argument", | ||
cfgPath: testUpgradeDiffConfig, | ||
args: []string{"bad-version"}, | ||
expectedError: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
parentFlags.cfgPath = tc.cfgPath | ||
if tc.setManifestPath { | ||
flags.apiServerManifestPath = tc.manifestPath | ||
flags.controllerManagerManifestPath = tc.manifestPath | ||
flags.schedulerManifestPath = tc.manifestPath | ||
} | ||
if err := runDiff(flags, tc.args); (err != nil) != tc.expectedError { | ||
t.Fatalf("expected error: %v, saw: %v, error: %v", tc.expectedError, (err != nil), err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
some-empty-file-to-diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
apiVersion: kubeadm.k8s.io/v1alpha1 | ||
kind: MasterConfiguration | ||
kubernetesVersion: 1.11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters