Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/cogctl/actions/bundle/install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ defmodule Cogctl.Actions.Bundle.Install do
{:templates, ?t, 'templates', {:string, 'templates'}, 'Path to your template directory'},
{:enabled, ?e, 'enable', {:boolean, false}, 'Enable bundle after installing'},
{:verbose, ?v, 'verbose', {:boolean, false}, 'Verbose output'},
{:force, ?f, 'force', {:boolean, false}, 'Force bundle installation even if a bundle with the same version is already installed'},
{:"relay-groups", :undefined, 'relay-groups', {:list, :undefined}, 'List of relay group names separated by commas to assign the bundle'}]
end

def run(options, _args, _config, endpoint) do
params = convert_to_params(options, [:bundle_or_path, :templates, :enabled, :verbose, :"relay-groups", :version])
params = convert_to_params(options, [:bundle_or_path, :templates, :enabled, :verbose, :"relay-groups", :version, :force])
with_authentication(endpoint, &do_install(&1, params))
end

Expand Down Expand Up @@ -103,7 +104,7 @@ defmodule Cogctl.Actions.Bundle.Install do
{:config, config} ->
with {:ok, amended_config} <- add_templates_from_dir(config, params.templates),
{:ok, valid_config} <- validate_config(amended_config) do
Client.bundle_install(endpoint, %{"config" => valid_config})
Client.bundle_install(endpoint, %{"config" => valid_config, "force" => params[:force]})
end
{:registry, {bundle, version}} ->
Client.bundle_install_from_registry(endpoint, bundle, version)
Expand Down
26 changes: 26 additions & 0 deletions test/cogctl/bundles_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ defmodule Cogctl.Actions.Bundles.Test do
end
end

test "force installing a bundle" do
config_path = BundleHelpers.create_config_file("testfoo")

use_cassette "force_installing_a_bundle", match_requests_on: [:request_body] do
# initial install
assert run("cogctl bundle install -v #{config_path}") =~ ~r"""
Bundle ID: .*
Version ID: .*
Name: testfoo
Version: 0.0.1
Status: Disabled
"""

# reinstall the same bundle with the force, -f, flag.
assert run("cogctl bundle install -v --force #{config_path}") =~ ~r"""
Bundle ID: .*
Version ID: .*
Name: testfoo
Version: 0.0.1
Status: Disabled
"""

BundleHelpers.cleanup
end
end

test "installing a bundle with templates" do
use_cassette "installing_with_templates", match_requests_on: [:request_body] do
config_path = BundleHelpers.create_config_file("testfoo")
Expand Down
191 changes: 191 additions & 0 deletions test/fixtures/cassettes/force_installing_a_bundle.json

Large diffs are not rendered by default.

311 changes: 22 additions & 289 deletions test/fixtures/cassettes/installing_with_templates.json

Large diffs are not rendered by default.