-
Notifications
You must be signed in to change notification settings - Fork 5k
Add hyperkit version check whether user's hyperkit is newer #5833
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
Merged
tstromberg
merged 4 commits into
kubernetes:master
from
govargo:fix-without-hyperkit-errormsg
Dec 19, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fcbf4d1
Add hyperkit version checker: whether user's hyperkit is new
govargo f9d4762
Improve hyperkit specific version check
govargo 39f7134
rename constant name and shorten warining message of version old
govargo b650600
refactor: remove warning log to avoid duplicate logging and remove usβ¦
govargo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors All rights reserved. | ||
|
||
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 hyperkit | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var ( | ||
versionOutputType1 = "hyperkit: v0.20190201-11-gc0dd46\n\nHomepage: https://github.com/docker/hyperkit\nLicense: BSD\n\n" | ||
versionOutputType2 = "hyperkit: 0.20190201\n\nHomepage: https://github.com/docker/hyperkit\nLicense: BSD\n\n" | ||
) | ||
|
||
func TestSplitHyperKitVersion(t *testing.T) { | ||
var tc = []struct { | ||
desc, version, expect string | ||
}{ | ||
{ | ||
desc: "split type1 output to YYYYMMDD format", | ||
version: "v.20190201-gc0dd46", | ||
expect: "20190201", | ||
}, | ||
{ | ||
desc: "split type2 output to YYYYMMDD format", | ||
version: "0.20190201", | ||
expect: "20190201", | ||
}, | ||
{ | ||
desc: "non split YYYYMMDD output to YYYYMMDD format", | ||
version: "20190201", | ||
expect: "20190201", | ||
}, | ||
{ | ||
desc: "split semver output to YYYYMMDD format", | ||
version: "v1.0.0", | ||
expect: "0", | ||
}, | ||
} | ||
for _, test := range tc { | ||
t.Run(test.desc, func(t *testing.T) { | ||
version := splitHyperKitVersion(test.version) | ||
if version != test.expect { | ||
t.Fatalf("Error %v expected but result %v", test.expect, version) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestConvertVersionToDate(t *testing.T) { | ||
var tc = []struct { | ||
desc, versionOutput, expect string | ||
}{ | ||
{ | ||
desc: "split type1 output to YYYYMMDD format", | ||
versionOutput: versionOutputType1, | ||
expect: "20190201", | ||
}, | ||
{ | ||
desc: "split type2 output to YYYYMMDD format", | ||
versionOutput: versionOutputType2, | ||
expect: "20190201", | ||
}, | ||
{ | ||
desc: "split semver output to YYYYMMDD format", | ||
versionOutput: "hyperkit: v1.0.0\n\nHomepage: https://github.com/docker/hyperkit\nLicense: BSD\n\n", | ||
expect: "0", | ||
}, | ||
} | ||
for _, test := range tc { | ||
t.Run(test.desc, func(t *testing.T) { | ||
version := convertVersionToDate(test.versionOutput) | ||
if version != test.expect { | ||
t.Fatalf("Error %v expected but result %v", test.expect, version) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsNewerVersion(t *testing.T) { | ||
var tc = []struct { | ||
desc, currentVersion, specificVersion string | ||
isNew bool | ||
}{ | ||
{ | ||
desc: "version check newer", | ||
currentVersion: "29991231", | ||
specificVersion: "20190802", | ||
isNew: true, | ||
}, | ||
{ | ||
desc: "version check equal", | ||
currentVersion: "20190802", | ||
specificVersion: "20190802", | ||
isNew: true, | ||
}, | ||
{ | ||
desc: "version check older", | ||
currentVersion: "20190201", | ||
specificVersion: "20190802", | ||
isNew: false, | ||
}, | ||
} | ||
for _, test := range tc { | ||
t.Run(test.desc, func(t *testing.T) { | ||
isNew, err := isNewerVersion(test.currentVersion, test.specificVersion) | ||
if err != nil { | ||
t.Fatalf("Got unexpected error %v", err) | ||
} | ||
if isNew != test.isNew { | ||
t.Fatalf("Error %v expected but result %v", test.isNew, isNew) | ||
} | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
isNewerVersion
should probably return the error rather than silently dropping it, so that the caller can determine what the right course of action is.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!
I changed that
isNewerVersion
returns error iferr != nil
.