summaryrefslogtreecommitdiff
path: root/spec/models/clusters
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/clusters')
-rw-r--r--spec/models/clusters/applications/prometheus_spec.rb59
-rw-r--r--spec/models/clusters/cluster_spec.rb6
-rw-r--r--spec/models/clusters/kubernetes_namespace_spec.rb2
-rw-r--r--spec/models/clusters/platforms/kubernetes_spec.rb32
4 files changed, 35 insertions, 64 deletions
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb
index 2250ef301aa..81708b0c2ed 100644
--- a/spec/models/clusters/applications/prometheus_spec.rb
+++ b/spec/models/clusters/applications/prometheus_spec.rb
@@ -27,65 +27,6 @@ describe Clusters::Applications::Prometheus do
end
end
- describe '#ready' do
- let(:project) { create(:project) }
- let(:cluster) { create(:cluster, projects: [project]) }
-
- it 'returns true when installed' do
- application = build(:clusters_applications_prometheus, :installed, cluster: cluster)
-
- expect(application).to be_ready
- end
-
- it 'returns false when not_installable' do
- application = build(:clusters_applications_prometheus, :not_installable, cluster: cluster)
-
- expect(application).not_to be_ready
- end
-
- it 'returns false when installable' do
- application = build(:clusters_applications_prometheus, :installable, cluster: cluster)
-
- expect(application).not_to be_ready
- end
-
- it 'returns false when scheduled' do
- application = build(:clusters_applications_prometheus, :scheduled, cluster: cluster)
-
- expect(application).not_to be_ready
- end
-
- it 'returns false when installing' do
- application = build(:clusters_applications_prometheus, :installing, cluster: cluster)
-
- expect(application).not_to be_ready
- end
-
- it 'returns false when errored' do
- application = build(:clusters_applications_prometheus, :errored, cluster: cluster)
-
- expect(application).not_to be_ready
- end
-
- it 'returns true when updating' do
- application = build(:clusters_applications_prometheus, :updating, cluster: cluster)
-
- expect(application).to be_ready
- end
-
- it 'returns true when updated' do
- application = build(:clusters_applications_prometheus, :updated, cluster: cluster)
-
- expect(application).to be_ready
- end
-
- it 'returns true when errored' do
- application = build(:clusters_applications_prometheus, :update_errored, cluster: cluster)
-
- expect(application).to be_ready
- end
- end
-
describe '#prometheus_client' do
context 'cluster is nil' do
it 'returns nil' do
diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb
index 92ce2b0999a..3feed4e9718 100644
--- a/spec/models/clusters/cluster_spec.rb
+++ b/spec/models/clusters/cluster_spec.rb
@@ -265,12 +265,12 @@ describe Clusters::Cluster do
it { is_expected.to be_valid }
end
- context 'when cluster has an invalid domain' do
- let(:cluster) { build(:cluster, domain: 'not-valid-domain') }
+ context 'when cluster is not a valid hostname' do
+ let(:cluster) { build(:cluster, domain: 'http://not.a.valid.hostname') }
it 'should add an error on domain' do
expect(subject).not_to be_valid
- expect(subject.errors[:domain].first).to eq('is not a fully qualified domain name')
+ expect(subject.errors[:domain].first).to eq('contains invalid characters (valid characters: [a-z0-9\\-])')
end
end
diff --git a/spec/models/clusters/kubernetes_namespace_spec.rb b/spec/models/clusters/kubernetes_namespace_spec.rb
index 235e2ee4e69..b865909c7fd 100644
--- a/spec/models/clusters/kubernetes_namespace_spec.rb
+++ b/spec/models/clusters/kubernetes_namespace_spec.rb
@@ -97,7 +97,7 @@ RSpec.describe Clusters::KubernetesNamespace, type: :model do
let(:platform) { create(:cluster_platform_kubernetes, api_url: api_url, ca_cert: ca_pem, token: token) }
let(:api_url) { 'https://kube.domain.com' }
- let(:ca_pem) { 'CA PEM DATA' }
+ let(:ca_pem) { File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem')) }
let(:token) { 'token' }
let(:kubeconfig) do
diff --git a/spec/models/clusters/platforms/kubernetes_spec.rb b/spec/models/clusters/platforms/kubernetes_spec.rb
index c273fa7e164..4068d98d8f7 100644
--- a/spec/models/clusters/platforms/kubernetes_spec.rb
+++ b/spec/models/clusters/platforms/kubernetes_spec.rb
@@ -114,6 +114,36 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
end
end
+ context 'ca_cert' do
+ let(:kubernetes) { build(:cluster_platform_kubernetes, ca_pem: ca_pem) }
+
+ context 'with a valid certificate' do
+ let(:ca_pem) { File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem')) }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'with an invalid certificate' do
+ let(:ca_pem) { "invalid" }
+
+ it { is_expected.to be_falsey }
+
+ context 'but the certificate is not being updated' do
+ before do
+ allow(kubernetes).to receive(:ca_cert_changed?).and_return(false)
+ end
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
+ context 'with no certificate' do
+ let(:ca_pem) { "" }
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
describe 'when using reserved namespaces' do
subject { build(:cluster_platform_kubernetes, namespace: namespace) }
@@ -202,7 +232,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
let!(:cluster) { create(:cluster, :project, platform_kubernetes: kubernetes) }
let(:kubernetes) { create(:cluster_platform_kubernetes, api_url: api_url, ca_cert: ca_pem) }
let(:api_url) { 'https://kube.domain.com' }
- let(:ca_pem) { 'CA PEM DATA' }
+ let(:ca_pem) { File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem')) }
subject { kubernetes.predefined_variables(project: cluster.project) }