-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
add custom parameters to structured tests #6055
add custom parameters to structured tests #6055
Conversation
Custom parameters can now be added to structured tests in form of yaml config list.
Codecov Report
@@ Coverage Diff @@
## master #6055 +/- ##
==========================================
- Coverage 70.55% 70.32% -0.24%
==========================================
Files 468 471 +3
Lines 18036 18082 +46
==========================================
- Hits 12726 12716 -10
- Misses 4375 4436 +61
+ Partials 935 930 -5
Continue to review full report at Codecov.
|
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 for your contribution! A few small changes.
@@ -491,6 +491,10 @@ type TestCase struct { | |||
// to run on that artifact. | |||
// For example: `["./test/*"]`. | |||
StructureTests []string `yaml:"structureTests,omitempty" skaffold:"filepath"` | |||
|
|||
// StructureTestArgs lists additional configuration arguments passed to `container-structure-test` binary. | |||
// For example: `["--driver tar", "--no-color", "-q"]`. |
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.
As I mention elsewhere in this review, we don't want to do arg parsing. But most long-form arguments support using an =
so we should be able to use:
// For example: `["--driver tar", "--no-color", "-q"]`. | |
// For example: `["--driver=tar", "--no-color", "-q"]`. |
@@ -86,7 +89,10 @@ func (cst *Runner) runStructureTests(ctx context.Context, out io.Writer, imageTa | |||
for _, f := range files { | |||
args = append(args, "--config", f) | |||
} | |||
|
|||
for _, customArg := range cst.structureTestArgs { | |||
splittedCustomArg := strings.Fields(customArg) |
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.
We require the user to be responsible for splitting arguments properly. Otherwise we need to deal with quoting issues, and YAML already makes that hard enough. Docker uses this approach too.
@@ -94,6 +94,44 @@ func TestIgnoreDockerNotFound(t *testing.T) { | |||
}) | |||
} | |||
|
|||
func TestCustomParams(t *testing.T) { | |||
const ( | |||
imageName = "image:tag" |
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.
Just inline this: you're using the string inline anyways further below.
workspace: tc.Workspace, | ||
localDaemon: localDaemon, | ||
imageIsLocal: imageIsLocal, | ||
structureTestArgs: tc.StructureTestArgs, |
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 think it might be better to move this up below line 51 with the structureTests
to keep the parameters together. localDaemon
and imageIsLocal
are internal matters.
expectedBaseCmd := "container-structure-test test -v warn --image " + imageName + " --config " + tmpDir.Path("test.yaml") | ||
t.Override(&util.DefaultExecCommand, testutil.CmdRun(expectedBaseCmd+" --driver tar --force --no-color -q --save")) | ||
|
||
structureTestArgs := []string{"--driver tar", "--force", "--no-color", "-q", "--save"} |
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.
expectedBaseCmd := "container-structure-test test -v warn --image " + imageName + " --config " + tmpDir.Path("test.yaml") | |
t.Override(&util.DefaultExecCommand, testutil.CmdRun(expectedBaseCmd+" --driver tar --force --no-color -q --save")) | |
structureTestArgs := []string{"--driver tar", "--force", "--no-color", "-q", "--save"} | |
expectedBaseCmd := "container-structure-test test -v warn --image image:tag --config " + tmpDir.Path("test.yaml") | |
t.Override(&util.DefaultExecCommand, testutil.CmdRun(expectedBaseCmd+" --driver=tar --force --no-color -q --save")) | |
structureTestArgs := []string{"--driver=tar", "--force", "--no-color", "-q", "--save"} |
imageName = "image:tag" | ||
) | ||
|
||
testutil.Run(t, "", func(t *testutil.T) { |
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 would be useful to have tests here for: nil
and an empty array too.
@briandealwis Thanks for your comments! I'll address them shortly and submit an updated PR. |
@briandealwis I added a new commit addressing your remarks, feel free to re-review if you're free. Thanks |
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.
This looks great — thanks!
- --driver=tar | ||
- -q | ||
- --no-color | ||
- --test-report=TEST_REPORT_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.
- --test-report=TEST_REPORT_NAME | |
- --test-report=TEST_REPORT_NAME |
Fixes: #5817
Description
Custom parameters can now be added to structured tests in form of yaml config list.