Tests, refactor and coverage on package opts#13694
Conversation
e2990f3 to
1e2ba46
Compare
opts/opts.go
Outdated
There was a problem hiding this comment.
why don't you fix it rather than leaving a comment? 😉
There was a problem hiding this comment.
Well, I was asking if this was ok before doing it 😸. Now that I know it is I will fix it 😉.
There was a problem hiding this comment.
Ok that's kinda what I guessed, it has to be there because it is used as a type ValidatorFctType func(val string) (string, error). I think I should just remove the comment for now 😝.
Environment(s) and thus Label(s) (that are validated the same way) are always valid, just rewritten a bit sometimes.
1e2ba46 to
3ee81b8
Compare
opts/envfile_test.go
Outdated
There was a problem hiding this comment.
IMO we're inconsistent. If you added a "=" after each of those you'd get an error like:
docker: poorly formatted environment: variable 'a b c' has white spaces.
Yet w/o the "=" it passes it thru to the container. We should either allow both or error both.
I think we should detect the spaces and error in both cases. Want to fix that as part of this?
There was a problem hiding this comment.
There is a certain consistency in the fact that we are able to run docker run -e "something with space" busybox /bin/sh ; although the environment variables is not set in the container. I should probably validate this too (ValidateEnv).
a64cde1 to
7d2c339
Compare
|
Ok, so I've updated the
For the sake of it, I wasn't sure if it was possible to define a environment variable with spaces, so I tried (with $ export SOME\ SPACES=value
bash: export: `SOME SPACES=value': not a valid identifier
$ export "SOME SPACES"=value
bash: export: `SOME SPACES=value': not a valid identifier |
|
yep - that's what I got in my testing as well. thanks!! |
7d2c339 to
dcc377d
Compare
|
LABEL call just stole code from ENV. It should follow the same standard of whatever ENV allows, I believe. |
dcc377d to
a89c57d
Compare
|
Rebased to master and move a test from #13879 in |
opts/envfile.go
Outdated
There was a problem hiding this comment.
minor thing, and up to you, but I think if len(data) > 1 would be better just because it'll be faster than looping over the string looking for =
There was a problem hiding this comment.
sounds about right, will do :)
b3c0d6c to
bfca3fe
Compare
opts/opts.go
Outdated
There was a problem hiding this comment.
I think we may need to externalize and then use validMountMode() from daemon/volumes.go since the list of modes is more than just rw and ro. What do you think?
There was a problem hiding this comment.
You're right 😸. I'll look at that this evening.
|
Just one question/comment! Looking good! |
bfca3fe to
cf9a020
Compare
There was a problem hiding this comment.
This one will not fail anymore, so removing it :).
There was a problem hiding this comment.
Meaning, now it is supposed to work with this syntax and not fail like on this test 😉.
|
@duglin I think it's done.. I'm not found of the move I made of |
|
@vdemeester yea, lets keep that code into volumes.go and just externalize validateMountMode() instead of moving it all into opt.go. To me, volumes (sort of) owns all that logic and the opts stuff is more like a user of it. |
|
@duglin The problem is there seems to be a cycle loop of import (if I import |
91fb81f to
37e4bef
Compare
|
@duglin quick update :
|
- Refactor opts.ValidatePath and add an opts.ValidateDevice ValidePath will now accept : containerPath:mode, hostPath:containerPath:mode and hostPath:containerPath. ValidateDevice will have the same behavior as current. - Refactor opts.ValidateEnv, opts.ParseEnvFile Environment variables will now be validated with the following definition : > Environment variables set by the user must have a name consisting > solely of alphabetics, numerics, and underscores - the first of > which must not be numeric. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
37e4bef to
dfc6c04
Compare
|
@duglin Another update 😅. |
|
@vdemeester thanks for the hard work! ping @LK4D4 you still ok with this? |
|
LGTM |
Tests, refactor and coverage on package opts
|
🎉 thanks!! |
|
🎉 😊 |
Update documentation according to opts updates (#13694)
|
Added impact labels, because the validation-rules for environment variables changed in this PR (see #14727) |
This is the time for
optsto get covered 🐸 and a little bit refactored.ValidateEnvandParseEnvFileuses a regexp to valide that it is a correct environment variable that is passed. The definition used :ValidateLabelis made consistent with theLABELinDockerfileas it allows multiple=likeLABEL label=value1=value2.There is a few
FIXMEin this one :ValidatePath(":/test")is valid, although it will fail after I thinkfunc ValidateEnv(val string) (string, error)always returnsnilfor error. I guess it's for coherence of returns with the other validate method, so I think I can remove myFIXMEcomment.There isFIXMEsforListOpts.GetAll()andListOpts.GetMapasking if we can remove it. They are used inrunconfig/parse.go;GetMapcould/should probably have another name but..Signed-off-by: Vincent Demeester vincent@sbr.pm