Skip to content

Commit

Permalink
Merge pull request #295 from zeari/prometheus_tests
Browse files Browse the repository at this point in the history
Add api specs for prometheus endpoints
  • Loading branch information
abellotti authored Jan 23, 2018
2 parents 9f9f4ee + 6454bd2 commit fb3a844
Showing 1 changed file with 75 additions and 11 deletions.
86 changes: 75 additions & 11 deletions spec/requests/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"port" => 18_443,
"hostname" => "sample-openshift.provider.com",
"ipaddress" => "100.200.300.3",
"security_protocol" => "something",
"security_protocol" => "ssl-without-validation",
"certificate_authority" => certificate_authority,
}
end
Expand All @@ -93,7 +93,7 @@
"role" => "default",
"hostname" => "sample-openshift-multi-end-point.provider.com",
"port" => 18_443,
"security_protocol" => "something",
"security_protocol" => "ssl-without-validation",
"certificate_authority" => certificate_authority,
},
"authentication" => {
Expand All @@ -108,7 +108,7 @@
"role" => "default",
"hostname" => "sample-openshift-multi-end-point.provider.com",
"port" => "28443",
"security_protocol" => "something else",
"security_protocol" => "ssl-without-validation",
"certificate_authority" => certificate_authority,
},
"authentication" => {
Expand All @@ -123,7 +123,7 @@
"role" => "hawkular",
"hostname" => "sample-openshift-multi-end-point.provider.com",
"port" => 1_443,
"security_protocol" => "something",
"security_protocol" => "ssl-without-validation",
"certificate_authority" => certificate_authority,
},
"authentication" => {
Expand All @@ -132,13 +132,48 @@
}
}
end
let(:sample_containers_multi_end_point) do
let(:prometheus_connection) do
{
"endpoint" => {
"role" => "prometheus",
"hostname" => "prometheus.example.com",
"port" => 443,
"security_protocol" => "ssl-without-validation"
},
"authentication" => {
"role" => "prometheus",
"auth_key" => SecureRandom.hex
}
}
end
let(:prometheus_alerts_connection) do
{
"endpoint" => {
"role" => "prometheus_alerts",
"hostname" => "prometheus.example.com",
"port" => 443,
"security_protocol" => "ssl-without-validation"
},
"authentication" => {
"role" => "prometheus_alerts",
"auth_key" => SecureRandom.hex
}
}
end
let(:sample_containers_multi_end_point_with_hawkular) do
{
"type" => containers_class,
"name" => "sample containers provider with multiple endpoints",
"name" => "sample containers provider with multiple endpoints and hawkular",
"connection_configurations" => [default_connection, hawkular_connection]
}
end
let(:sample_containers_multi_end_point_with_prometheus) do
{
"type" => containers_class,
"name" => "sample containers provider with multiple endpoints and prometheus",
"connection_configurations" => [prometheus_alerts_connection, default_connection, prometheus_connection]
}
end

def have_endpoint_attributes(expected_hash)
h = expected_hash.slice(*ENDPOINT_ATTRS)
Expand Down Expand Up @@ -573,15 +608,15 @@ def token(connection)
connection["authentication"]["auth_key"]
end

it "supports provider with multiple endpoints creation" do
it "supports provider with multiple endpoints creation with hawkular" do
api_basic_authorize collection_action_identifier(:providers, :create)

post(api_providers_url, :params => gen_request(:create, sample_containers_multi_end_point))
post(api_providers_url, :params => gen_request(:create, sample_containers_multi_end_point_with_hawkular))

expect(response).to have_http_status(:ok)
expected = {"id" => a_kind_of(String),
"type" => containers_class,
"name" => "sample containers provider with multiple endpoints"}
"name" => "sample containers provider with multiple endpoints and hawkular"}

results = response.parsed_body["results"]
expect(results.first).to include(expected)
Expand All @@ -596,6 +631,35 @@ def token(connection)
)
expect(provider.authentication_token(:hawkular)).to eq(token(hawkular_connection))
end

it "supports provider with multiple endpoints creation and prometheus" do
api_basic_authorize collection_action_identifier(:providers, :create)

post(api_providers_url, :params => gen_request(:create, sample_containers_multi_end_point_with_prometheus))

expect(response).to have_http_status(:ok)
expected = {"id" => a_kind_of(String),
"type" => containers_class,
"name" => "sample containers provider with multiple endpoints and prometheus"}

results = response.parsed_body["results"]
expect(results.first).to include(expected)

provider_id = results.first["id"]
provider = ExtManagementSystem.find(provider_id)
expect(provider).to have_endpoint_attributes(default_connection["endpoint"])
expect(provider.authentication_token).to eq(token(default_connection))

expect(provider.connection_configurations.prometheus.endpoint).to have_endpoint_attributes(
prometheus_connection["endpoint"]
)

expect(provider.connection_configurations.prometheus_alerts.endpoint).to have_endpoint_attributes(
prometheus_alerts_connection["endpoint"]
)
expect(provider.authentication_token(:prometheus)).to eq(token(prometheus_connection))
expect(provider.authentication_token(:prometheus_alerts)).to eq(token(prometheus_alerts_connection))
end
end
end
end
Expand Down Expand Up @@ -683,7 +747,7 @@ def token(connection)
it "does not schedule a new credentials check if endpoint does not change" do
api_basic_authorize collection_action_identifier(:providers, :edit)

provider = FactoryGirl.create(:ext_management_system, sample_containers_multi_end_point)
provider = FactoryGirl.create(:ext_management_system, sample_containers_multi_end_point_with_hawkular)
MiqQueue.where(:method_name => "authentication_check_types",
:class_name => "ExtManagementSystem",
:instance_id => provider.id).delete_all
Expand All @@ -702,7 +766,7 @@ def token(connection)
it "schedules a new credentials check if endpoint change" do
api_basic_authorize collection_action_identifier(:providers, :edit)

provider = FactoryGirl.create(:ext_management_system, sample_containers_multi_end_point)
provider = FactoryGirl.create(:ext_management_system, sample_containers_multi_end_point_with_hawkular)
MiqQueue.where(:method_name => "authentication_check_types",
:class_name => "ExtManagementSystem",
:instance_id => provider.id).delete_all
Expand Down

0 comments on commit fb3a844

Please sign in to comment.