Skip to content
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

Empty cluster bug #593

Merged
merged 2 commits into from
Jul 16, 2020
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: 4 additions & 1 deletion apps/dashboard/app/models/batch_connect/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def link
# The clusters the batch connect app is configured to use
# @return [Array<String>, []] the clusters the app wants to use
def configured_clusters
Array.wrap(form_config.fetch(:cluster, nil)).compact.map { |c| c.to_s.strip.eql?("*") ? ".*" : c.to_s.strip }
Array.wrap(form_config.fetch(:cluster, nil))
.select { |c| !c.to_s.strip.empty? }
.map { |c| c.to_s.strip.eql?("*") ? ".*" : c.to_s.strip }
.compact
end

# The clusters that the batch connect app can use. It's a combination
Expand Down
33 changes: 33 additions & 0 deletions apps/dashboard/test/models/batch_connect/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,37 @@ def bad_clusters
assert_equal [], app.clusters
}
end

test "app with empty configured cluster is not configured with any cluster" do
Dir.mktmpdir { |dir|
r = PathRouter.new(dir)
r.path.join("form.yml").write("cluster: \"\"")

app = BatchConnect::App.new(router: r)
# it's valid but there are no clusters. Empty configurations are the same as
# user defined
assert app.valid?
assert_equal [], app.configured_clusters
assert_equal [], app.clusters
}
end

test "app disregards empty cluster strings" do
OodAppkit.stubs(:clusters).returns(good_clusters + bad_clusters)

Dir.mktmpdir { |dir|
r = PathRouter.new(dir)
# note the empty string and the string with whitespace
r.path.join("form.yml").write("cluster:\n - owens\n - \"\"\n - \" \"")

app = BatchConnect::App.new(router: r)

assert app.valid?
# only owens gets through
assert_equal [ 'owens' ], app.configured_clusters
assert_equal [ OodCore::Cluster.new({id: 'owens', job: {foo: 'bar'}}) ], app.clusters
}
end


end