Commit Graph

17 Commits

Author SHA1 Message Date
Sebastiaan van Stijn 2c0e93063b
bump gotest.tools v3.0.1 for compatibility with Go 1.14
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-23 00:28:55 +01:00
Sebastiaan van Stijn aafe3df8b3
cli/compose/template: Using the variable on range scope `tc` in function literal (scopelint)
```
cli/compose/template/template_test.go:279:31: Using the variable on range scope `tc` in function literal (scopelint)
			actual := ExtractVariables(tc.dict, defaultPattern)
			                           ^
cli/compose/template/template_test.go:280:41: Using the variable on range scope `tc` in function literal (scopelint)
			assert.Check(t, is.DeepEqual(actual, tc.expected))
			                                     ^
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-31 19:22:38 +01:00
Sebastiaan van Stijn ec3daea021
Fix substitution with non-empty env-var
Due to a typo, substitution would not work if the given
environment-variable was set.

Given the following docker compose file;

```yaml
version: "3.7"

services:
  app:
    image: nginx:${version:-latest}
```

Deploying a stack with `$version` set would ignore the `$version`
environment variable, and use the default value instead;

```bash
version=alpine docker stack deploy -c docker-compose.yml foobar

Creating network foobar_default
Creating service foobar_app

docker service ls

ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
rskkjxe6sm0w        foobar_app          replicated          1/1                 nginx:latest
```

This patch also fixes "soft default" not detecting empty environment variables,
only non-set environment variables.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-09-25 22:20:25 +02:00
Vincent Demeester 9cd7c1361c
Migrate `TestExtractVariables` to subtests…
… as suggested in previous PR comment.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-08-07 16:06:13 +02:00
Vincent Demeester 4c87725c35
Allow custom pattern when extracting variable…
… as it is possible to do it when interpolating. It also fixes when
there is 2 variables on the same *value* (in the composefile, on the
same line)

Finaly, renaming the default, used in cli, pattern to `defaultPattern`
to not be shadowed unintentionally.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-08-02 16:50:40 +02:00
Vincent Demeester afb87e42f2
Add a new `ExtractVariables` function to `compose/template` package
It allows to get easily all the variables defined in a
composefile (the `map[string]interface{}` representation that
`loader.ParseYAML` returns at least) and their default value too.

This commit also does some small function extract on substitution
funcs to reduce a tiny bit duplication.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-08-01 16:12:49 +02:00
Vincent Demeester 9fdd14f399
Add options to the compose loader
- Add the possibility to skip interpolation
- Add the possibility to skip schema validation
- Allow customizing the substitution function, to add special cases.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-25 17:15:26 +02:00
Vincent Demeester 2c4de4fb5e
Update tests to use gotest.tools 👼
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-08 18:24:26 +02:00
Daniel Nephin baf65a5502 Convert to assert.NilError
Using:

  git grep -l '^\s\+assert\.Check(t, err)$' | \
    xargs sed -i -e 's/^\(\s\+assert\)\.Check(t, err)$/\1.NilError(t, err)/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-06 15:27:34 -05:00
Daniel Nephin 5155cda716 Post migration fixes
Fix tests that failed when using cmp.Compare()
internal/test/testutil/assert
InDelta
Fix DeepEqual with kube metav1.Time
Convert some ErrorContains to assert

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-05 19:41:17 -05:00
Daniel Nephin 39c2ca57c1 Automated migration
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-05 19:41:17 -05:00
Daniel Nephin 93615dd967 Update some assertions.
and fix some tests

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-05 17:15:24 -05:00
Arash Deshmeh 5d8ce59a25 fix the error message in Substitute function
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
2018-02-26 15:29:17 -05:00
Arash Deshmeh e33bc48752 Added error message check to TestMandatoryVariableErrors test
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
2018-02-26 15:29:17 -05:00
Daniel Nephin ce544823b6 Refactor substitute to reduce cyclo complexity
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-02-26 15:29:17 -05:00
Arash Deshmeh 99ecf57c6c added support for mandatory variables to cli/compose
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
2018-02-26 15:29:17 -05:00
Daniel Nephin 1630fc40f8 Import docker/docker/cli
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
2017-04-17 17:40:59 -04:00