Skip to content

Commit

Permalink
fix: rename --provisioner to --provisioners and add a test
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Meier <[email protected]>
  • Loading branch information
astromechza committed Sep 13, 2024
1 parent 87fab57 commit 29c06e5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ Examples:
score-compose init --no-sample
# Optionally loading in provisoners from a remote url
score-compose init --provisioner https://raw.githubusercontent.com/user/repo/main/example.yaml
score-compose init --provisioners https://raw.githubusercontent.com/user/repo/main/example.yaml
Flags:
-f, --file string The score file to initialize (default "./score.yaml")
-h, --help help for init
-p, --project string Set the name of the docker compose project (defaults to the current directory name)
--provisioner stringArray A provisioner file to install. Supports http://host/file, https://host/file, git-ssh://git@host/repo.git/file, and git-https://host/repo.git/file formats.
-f, --file string The score file to initialize (default "./score.yaml")
-h, --help help for init
--no-sample Disable generation of the sample score file
-p, --project string Set the name of the docker compose project (defaults to the current directory name)
--provisioner stringArray A provisioner file to install. Supports http://host/file, https://host/file, git-ssh://git@host/repo.git/file, and git-https://host/repo.git/file formats.
Global Flags:
--quiet Mute any logging output
Expand Down
4 changes: 2 additions & 2 deletions examples/06-resource-provisioning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ files are matched first before `zz-default.provisioners.yaml`.

### Installing provisioner files

To easily install provisioners, `score-compose` provides the `--provisioner` flag for `init`, which downloads the provisioner
To easily install provisioners, `score-compose` provides the `--provisioners` flag for `init`, which downloads the provisioner
file via a URL and installs it with the highest priority.

For example, when running the following, the provisioners file B will be matched before A because B was installed after A:

```
score-compose init --provisioner https://example.com/provisioner-A.yaml --provisioners https://example.com/provisioner-B.yaml
score-compose init --provisioners https://example.com/provisioner-A.yaml --provisionerss https://example.com/provisioner-B.yaml
```

The provisioners can be loaded from the following kinds of urls:
Expand Down
6 changes: 3 additions & 3 deletions internal/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ resources: {}
initCmdFileFlag = "file"
initCmdFileProjectFlag = "project"
initCmdFileNoSampleFlag = "no-sample"
initCmdProvisionerFlag = "provisioner"
initCmdProvisionerFlag = "provisioners"
)

//go:embed default.provisioners.yaml
Expand All @@ -90,7 +90,7 @@ not be checked into source control. Add it to your .gitignore file if you use Gi
The project name will be used as a Docker compose project name when the final compose files are written. This name
acts as a namespace when multiple score files and containers are used.
Custom provisioners can be installed by uri using the --provisioner flag. The provisioners will be installed and take
Custom provisioners can be installed by uri using the --provisioners flag. The provisioners will be installed and take
precedence in the order they are defined over the default provisioners. If init has already been called with provisioners
the new provisioners will take precedence.
`,
Expand All @@ -105,7 +105,7 @@ the new provisioners will take precedence.
score-compose init --no-sample
# Optionally loading in provisoners from a remote url
score-compose init --provisioner https://raw.githubusercontent.com/user/repo/main/example.yaml`,
score-compose init --provisioners https://raw.githubusercontent.com/user/repo/main/example.yaml`,

// don't print the errors - we print these ourselves in main()
SilenceErrors: true,
Expand Down
46 changes: 39 additions & 7 deletions internal/command/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/score-spec/score-compose/internal/project"
"github.com/score-spec/score-compose/internal/provisioners/loader"
)

func TestInitHelp(t *testing.T) {
Expand All @@ -40,7 +41,7 @@ not be checked into source control. Add it to your .gitignore file if you use Gi
The project name will be used as a Docker compose project name when the final compose files are written. This name
acts as a namespace when multiple score files and containers are used.
Custom provisioners can be installed by uri using the --provisioner flag. The provisioners will be installed and take
Custom provisioners can be installed by uri using the --provisioners flag. The provisioners will be installed and take
precedence in the order they are defined over the default provisioners. If init has already been called with provisioners
the new provisioners will take precedence.
Expand All @@ -59,14 +60,14 @@ Examples:
score-compose init --no-sample
# Optionally loading in provisoners from a remote url
score-compose init --provisioner https://raw.githubusercontent.com/user/repo/main/example.yaml
score-compose init --provisioners https://raw.githubusercontent.com/user/repo/main/example.yaml
Flags:
-f, --file string The score file to initialize (default "./score.yaml")
-h, --help help for init
--no-sample Disable generation of the sample score file
-p, --project string Set the name of the docker compose project (defaults to the current directory name)
--provisioner stringArray A provisioner file to install. Supports http://host/file, https://host/file, git-ssh://git@host/repo.git/file, and git-https://host/repo.git/file formats.
-f, --file string The score file to initialize (default "./score.yaml")
-h, --help help for init
--no-sample Disable generation of the sample score file
-p, --project string Set the name of the docker compose project (defaults to the current directory name)
--provisioners stringArray A provisioner file to install. Supports http://host/file, https://host/file, git-ssh://git@host/repo.git/file, and git-https://host/repo.git/file formats.
Global Flags:
--quiet Mute any logging output
Expand Down Expand Up @@ -229,3 +230,34 @@ func TestInitNominal_run_twice(t *testing.T) {
assert.Equal(t, map[string]interface{}{}, sd.State.SharedState)
}
}

func TestInitWithProvisioners(t *testing.T) {
td := t.TempDir()
wd, _ := os.Getwd()
require.NoError(t, os.Chdir(td))
defer func() {
require.NoError(t, os.Chdir(wd))
}()

td2 := t.TempDir()
assert.NoError(t, os.WriteFile(filepath.Join(td2, "one.provisioners.yaml"), []byte(`
- uri: template://one
type: thing
outputs: "{}"
`), 0644))
assert.NoError(t, os.WriteFile(filepath.Join(td2, "two.provisioners.yaml"), []byte(`
- uri: template://two
type: thing
outputs: "{}"
`), 0644))

stdout, stderr, err := executeAndResetCommand(context.Background(), rootCmd, []string{"init", "--provisioners", filepath.Join(td2, "one.provisioners.yaml"), "--provisioners", "file://" + filepath.Join(td2, "two.provisioners.yaml")})
assert.NoError(t, err)
assert.Equal(t, "", stdout)
assert.NotEqual(t, "", strings.TrimSpace(stderr))

provs, err := loader.LoadProvisionersFromDirectory(filepath.Join(td, ".score-compose"), loader.DefaultSuffix)
assert.NoError(t, err)
assert.Equal(t, "template://two", provs[0].Uri())
assert.Equal(t, "template://one", provs[1].Uri())
}

0 comments on commit 29c06e5

Please sign in to comment.