summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2017-11-07 13:53:35 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2017-11-07 13:53:35 +0100
commita906752d7f585c3122f47404e3f80f098e5bf223 (patch)
tree05f2ad02b8b4c55cb6d660d54476feacfcfd41d0 /spec
parentfd9be1dd1f077a33e5ab15e8273fb726cbbc6fcc (diff)
parent67e12219bf6257568f91c1a9c883e4821337c80d (diff)
downloadgitlab-ce-a906752d7f585c3122f47404e3f80f098e5bf223.tar.gz
Merge branch '38464-k8s-apps' into add-ingress-to-cluster-applications
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/clusters/applications/helm.rb13
-rw-r--r--spec/features/copy_as_gfm_spec.rb4
-rw-r--r--spec/javascripts/behaviors/copy_as_gfm_spec.js47
-rw-r--r--spec/javascripts/clusters/clusters_bundle_spec.js30
-rw-r--r--spec/javascripts/clusters/components/application_row_spec.js4
-rw-r--r--spec/javascripts/copy_as_gfm_spec.js49
-rw-r--r--spec/javascripts/shortcuts_issuable_spec.js4
-rw-r--r--spec/lib/gitlab/import_export/all_models.yml16
-rw-r--r--spec/models/clusters/applications/helm_spec.rb10
-rw-r--r--spec/serializers/cluster_application_entity_spec.rb4
-rw-r--r--spec/serializers/cluster_entity_spec.rb4
-rw-r--r--spec/services/clusters/applications/check_installation_progress_service_spec.rb21
-rw-r--r--spec/services/clusters/applications/finalize_installation_service_spec.rb32
-rw-r--r--spec/services/clusters/applications/install_service_spec.rb16
-rw-r--r--spec/services/clusters/applications/schedule_installation_service_spec.rb2
15 files changed, 97 insertions, 159 deletions
diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb
index fd956097115..23818f19edf 100644
--- a/spec/factories/clusters/applications/helm.rb
+++ b/spec/factories/clusters/applications/helm.rb
@@ -1,33 +1,24 @@
FactoryGirl.define do
- factory :applications_helm, class: Clusters::Applications::Helm do
- trait :cluster do
- before(:create) do |app, _|
- app.cluster = create(:cluster)
- end
- end
+ factory :cluster_applications_helm, class: Clusters::Applications::Helm do
+ cluster factory: %i(cluster provided_by_gcp)
trait :installable do
- cluster
status 0
end
trait :scheduled do
- cluster
status 1
end
trait :installing do
- cluster
status 2
end
trait :installed do
- cluster
status 3
end
trait :errored do
- cluster
status(-1)
status_reason 'something went wrong'
end
diff --git a/spec/features/copy_as_gfm_spec.rb b/spec/features/copy_as_gfm_spec.rb
index c6ba1211b9e..1fcb8d5bc67 100644
--- a/spec/features/copy_as_gfm_spec.rb
+++ b/spec/features/copy_as_gfm_spec.rb
@@ -664,7 +664,7 @@ describe 'Copy as GFM', :js do
def html_to_gfm(html, transformer = 'transformGFMSelection', target: nil)
js = <<-JS.strip_heredoc
(function(html) {
- var transformer = window.gl.CopyAsGFM[#{transformer.inspect}];
+ var transformer = window.CopyAsGFM[#{transformer.inspect}];
var node = document.createElement('div');
$(html).each(function() { node.appendChild(this) });
@@ -678,7 +678,7 @@ describe 'Copy as GFM', :js do
node = transformer(node, target);
if (!node) return null;
- return window.gl.CopyAsGFM.nodeToGFM(node);
+ return window.CopyAsGFM.nodeToGFM(node);
})("#{escape_javascript(html)}")
JS
page.evaluate_script(js)
diff --git a/spec/javascripts/behaviors/copy_as_gfm_spec.js b/spec/javascripts/behaviors/copy_as_gfm_spec.js
new file mode 100644
index 00000000000..b8155144e2a
--- /dev/null
+++ b/spec/javascripts/behaviors/copy_as_gfm_spec.js
@@ -0,0 +1,47 @@
+import { CopyAsGFM } from '~/behaviors/copy_as_gfm';
+
+describe('CopyAsGFM', () => {
+ describe('CopyAsGFM.pasteGFM', () => {
+ function callPasteGFM() {
+ const e = {
+ originalEvent: {
+ clipboardData: {
+ getData(mimeType) {
+ // When GFM code is copied, we put the regular plain text
+ // on the clipboard as `text/plain`, and the GFM as `text/x-gfm`.
+ // This emulates the behavior of `getData` with that data.
+ if (mimeType === 'text/plain') {
+ return 'code';
+ }
+ if (mimeType === 'text/x-gfm') {
+ return '`code`';
+ }
+ return null;
+ },
+ },
+ },
+ preventDefault() {},
+ };
+
+ CopyAsGFM.pasteGFM(e);
+ }
+
+ it('wraps pasted code when not already in code tags', () => {
+ spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => {
+ const insertedText = textFunc('This is code: ', '');
+ expect(insertedText).toEqual('`code`');
+ });
+
+ callPasteGFM();
+ });
+
+ it('does not wrap pasted code when already in code tags', () => {
+ spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => {
+ const insertedText = textFunc('This is code: `', '`');
+ expect(insertedText).toEqual('code');
+ });
+
+ callPasteGFM();
+ });
+ });
+});
diff --git a/spec/javascripts/clusters/clusters_bundle_spec.js b/spec/javascripts/clusters/clusters_bundle_spec.js
index 86e9cb22be8..027e8001053 100644
--- a/spec/javascripts/clusters/clusters_bundle_spec.js
+++ b/spec/javascripts/clusters/clusters_bundle_spec.js
@@ -49,7 +49,7 @@ describe('Clusters', () => {
helm: { status: APPLICATION_INSTALLABLE, title: 'Helm Tiller' },
});
- expect(document.querySelector('.js-cluster-application-notice.hidden')).toBeDefined();
+ expect(document.querySelector('.js-cluster-application-notice .flash-text')).toBeNull();
});
it('shows an alert when something gets newly installed', () => {
@@ -61,8 +61,8 @@ describe('Clusters', () => {
helm: { status: APPLICATION_INSTALLED, title: 'Helm Tiller' },
});
- expect(document.querySelector('.js-cluster-application-notice:not(.hidden)')).toBeDefined();
- expect(document.querySelector('.js-cluster-application-notice').textContent.trim()).toEqual('Helm Tiller was successfully installed on your cluster');
+ expect(document.querySelector('.js-cluster-application-notice .flash-text')).toBeDefined();
+ expect(document.querySelector('.js-cluster-application-notice .flash-text').textContent.trim()).toEqual('Helm Tiller was successfully installed on your cluster');
});
it('shows an alert when multiple things gets newly installed', () => {
@@ -76,28 +76,8 @@ describe('Clusters', () => {
ingress: { status: APPLICATION_INSTALLED, title: 'Ingress' },
});
- expect(document.querySelector('.js-cluster-application-notice:not(.hidden)')).toBeDefined();
- expect(document.querySelector('.js-cluster-application-notice').textContent.trim()).toEqual('Helm Tiller, Ingress was successfully installed on your cluster');
- });
-
- it('hides existing alert when we call again and nothing is newly installed', () => {
- const installedState = {
- ...INITIAL_APP_MAP,
- helm: { status: APPLICATION_INSTALLED, title: 'Helm Tiller' },
- };
-
- // Show the banner
- cluster.checkForNewInstalls({
- ...INITIAL_APP_MAP,
- helm: { status: APPLICATION_INSTALLING, title: 'Helm Tiller' },
- }, installedState);
-
- expect(document.querySelector('.js-cluster-application-notice:not(.hidden)')).toBeDefined();
-
- // Banner should go back hidden
- cluster.checkForNewInstalls(installedState, installedState);
-
- expect(document.querySelector('.js-cluster-application-notice.hidden')).toBeDefined();
+ expect(document.querySelector('.js-cluster-application-notice .flash-text')).toBeDefined();
+ expect(document.querySelector('.js-cluster-application-notice .flash-text').textContent.trim()).toEqual('Helm Tiller, Ingress was successfully installed on your cluster');
});
});
diff --git a/spec/javascripts/clusters/components/application_row_spec.js b/spec/javascripts/clusters/components/application_row_spec.js
index 392cebc5e35..e671c18e1a5 100644
--- a/spec/javascripts/clusters/components/application_row_spec.js
+++ b/spec/javascripts/clusters/components/application_row_spec.js
@@ -117,7 +117,7 @@ describe('Application Row', () => {
expect(vm.installButtonDisabled).toEqual(true);
});
- it('has disabled "Install" when APPLICATION_ERROR', () => {
+ it('has enabled "Install" when APPLICATION_ERROR', () => {
vm = mountComponent(ApplicationRow, {
...DEFAULT_APPLICATION_STATE,
status: APPLICATION_ERROR,
@@ -125,7 +125,7 @@ describe('Application Row', () => {
expect(vm.installButtonLabel).toEqual('Install');
expect(vm.installButtonLoading).toEqual(false);
- expect(vm.installButtonDisabled).toEqual(true);
+ expect(vm.installButtonDisabled).toEqual(false);
});
it('has loading "Install" when REQUEST_LOADING', () => {
diff --git a/spec/javascripts/copy_as_gfm_spec.js b/spec/javascripts/copy_as_gfm_spec.js
deleted file mode 100644
index ded450749d3..00000000000
--- a/spec/javascripts/copy_as_gfm_spec.js
+++ /dev/null
@@ -1,49 +0,0 @@
-import '~/copy_as_gfm';
-
-(() => {
- describe('gl.CopyAsGFM', () => {
- describe('gl.CopyAsGFM.pasteGFM', () => {
- function callPasteGFM() {
- const e = {
- originalEvent: {
- clipboardData: {
- getData(mimeType) {
- // When GFM code is copied, we put the regular plain text
- // on the clipboard as `text/plain`, and the GFM as `text/x-gfm`.
- // This emulates the behavior of `getData` with that data.
- if (mimeType === 'text/plain') {
- return 'code';
- }
- if (mimeType === 'text/x-gfm') {
- return '`code`';
- }
- return null;
- },
- },
- },
- preventDefault() {},
- };
-
- window.gl.CopyAsGFM.pasteGFM(e);
- }
-
- it('wraps pasted code when not already in code tags', () => {
- spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => {
- const insertedText = textFunc('This is code: ', '');
- expect(insertedText).toEqual('`code`');
- });
-
- callPasteGFM();
- });
-
- it('does not wrap pasted code when already in code tags', () => {
- spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => {
- const insertedText = textFunc('This is code: `', '`');
- expect(insertedText).toEqual('code');
- });
-
- callPasteGFM();
- });
- });
- });
-})();
diff --git a/spec/javascripts/shortcuts_issuable_spec.js b/spec/javascripts/shortcuts_issuable_spec.js
index f6320db8dc4..5d6a885d4cc 100644
--- a/spec/javascripts/shortcuts_issuable_spec.js
+++ b/spec/javascripts/shortcuts_issuable_spec.js
@@ -1,6 +1,8 @@
-import '~/copy_as_gfm';
+import initCopyAsGFM from '~/behaviors/copy_as_gfm';
import ShortcutsIssuable from '~/shortcuts_issuable';
+initCopyAsGFM();
+
describe('ShortcutsIssuable', () => {
const fixtureName = 'merge_requests/diff_comment.html.raw';
preloadFixtures(fixtureName);
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml
index 6eb266a7b94..bc5c481d3a7 100644
--- a/spec/lib/gitlab/import_export/all_models.yml
+++ b/spec/lib/gitlab/import_export/all_models.yml
@@ -147,22 +147,6 @@ deploy_keys:
- user
- deploy_keys_projects
- projects
-clusters:
-- application_helm
-- cluster_projects
-- projects
-- user
-- provider_gcp
-- platform_kubernetes
-cluster_projects:
-- projects
-- clusters
-provider_gcp:
-- cluster
-platform_kubernetes:
-- cluster
-application_helm:
-- cluster
services:
- project
- service_hook
diff --git a/spec/models/clusters/applications/helm_spec.rb b/spec/models/clusters/applications/helm_spec.rb
index 54fce7d886a..44fb60f0ed0 100644
--- a/spec/models/clusters/applications/helm_spec.rb
+++ b/spec/models/clusters/applications/helm_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe Clusters::Applications::Helm, type: :model do
describe 'status state machine' do
describe '#make_installing' do
- subject { create(:applications_helm, :scheduled) }
+ subject { create(:cluster_applications_helm, :scheduled) }
it 'is installing' do
subject.make_installing!
@@ -38,7 +38,7 @@ RSpec.describe Clusters::Applications::Helm, type: :model do
end
describe '#make_installed' do
- subject { create(:applications_helm, :installing) }
+ subject { create(:cluster_applications_helm, :installing) }
it 'is installed' do
subject.make_installed
@@ -48,7 +48,7 @@ RSpec.describe Clusters::Applications::Helm, type: :model do
end
describe '#make_errored' do
- subject { create(:applications_helm, :installing) }
+ subject { create(:cluster_applications_helm, :installing) }
let(:reason) { 'some errors' }
it 'is errored' do
@@ -60,7 +60,7 @@ RSpec.describe Clusters::Applications::Helm, type: :model do
end
describe '#make_scheduled' do
- subject { create(:applications_helm, :installable) }
+ subject { create(:cluster_applications_helm, :installable) }
it 'is scheduled' do
subject.make_scheduled
@@ -69,7 +69,7 @@ RSpec.describe Clusters::Applications::Helm, type: :model do
end
describe 'when was errored' do
- subject { create(:applications_helm, :errored) }
+ subject { create(:cluster_applications_helm, :errored) }
it 'clears #status_reason' do
expect(subject.status_reason).not_to be_nil
diff --git a/spec/serializers/cluster_application_entity_spec.rb b/spec/serializers/cluster_application_entity_spec.rb
index 61cebcefa28..8a3a081adf8 100644
--- a/spec/serializers/cluster_application_entity_spec.rb
+++ b/spec/serializers/cluster_application_entity_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe ClusterApplicationEntity do
describe '#as_json' do
- let(:application) { build(:applications_helm) }
+ let(:application) { build(:cluster_applications_helm) }
subject { described_class.new(application).as_json }
it 'has name' do
@@ -18,7 +18,7 @@ describe ClusterApplicationEntity do
end
context 'when application is errored' do
- let(:application) { build(:applications_helm, :errored) }
+ let(:application) { build(:cluster_applications_helm, :errored) }
it 'has corresponded data' do
expect(subject[:status]).to eq(:errored)
diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb
index 67977e30264..f50f5999bfc 100644
--- a/spec/serializers/cluster_entity_spec.rb
+++ b/spec/serializers/cluster_entity_spec.rb
@@ -29,8 +29,8 @@ describe ClusterEntity do
context 'when provider type is user' do
let(:cluster) { create(:cluster, provider_type: :user) }
- it 'has nil' do
- expect(subject[:status]).to be_nil
+ it 'has corresponded data' do
+ expect(subject[:status]).to eq(:created)
expect(subject[:status_reason]).to be_nil
end
end
diff --git a/spec/services/clusters/applications/check_installation_progress_service_spec.rb b/spec/services/clusters/applications/check_installation_progress_service_spec.rb
index fe04fac9613..75fc05d36e9 100644
--- a/spec/services/clusters/applications/check_installation_progress_service_spec.rb
+++ b/spec/services/clusters/applications/check_installation_progress_service_spec.rb
@@ -3,14 +3,14 @@ require 'spec_helper'
describe Clusters::Applications::CheckInstallationProgressService do
RESCHEDULE_PHASES = Gitlab::Kubernetes::Pod::PHASES - [Gitlab::Kubernetes::Pod::SUCCEEDED, Gitlab::Kubernetes::Pod::FAILED].freeze
- let(:application) { create(:applications_helm, :installing) }
+ let(:application) { create(:cluster_applications_helm, :installing) }
let(:service) { described_class.new(application) }
let(:phase) { Gitlab::Kubernetes::Pod::UNKNOWN }
let(:errors) { nil }
shared_examples 'a terminated installation' do
- it 'finalize the installation' do
- expect(service).to receive(:finalize_installation).once
+ it 'removes the installation POD' do
+ expect(service).to receive(:remove_installation_pod).once
service.execute
end
@@ -23,7 +23,7 @@ describe Clusters::Applications::CheckInstallationProgressService do
context 'when not timeouted' do
it 'reschedule a new check' do
expect(ClusterWaitForAppInstallationWorker).to receive(:perform_in).once
- expect(service).not_to receive(:finalize_installation)
+ expect(service).not_to receive(:remove_installation_pod)
service.execute
@@ -33,7 +33,7 @@ describe Clusters::Applications::CheckInstallationProgressService do
end
context 'when timeouted' do
- let(:application) { create(:applications_helm, :timeouted) }
+ let(:application) { create(:cluster_applications_helm, :timeouted) }
it_behaves_like 'a terminated installation'
@@ -53,7 +53,7 @@ describe Clusters::Applications::CheckInstallationProgressService do
expect(service).to receive(:installation_phase).once.and_return(phase)
allow(service).to receive(:installation_errors).and_return(errors)
- allow(service).to receive(:finalize_installation).and_return(nil)
+ allow(service).to receive(:remove_installation_pod).and_return(nil)
end
describe '#execute' do
@@ -61,6 +61,15 @@ describe Clusters::Applications::CheckInstallationProgressService do
let(:phase) { Gitlab::Kubernetes::Pod::SUCCEEDED }
it_behaves_like 'a terminated installation'
+
+ it 'make the application installed' do
+ expect(ClusterWaitForAppInstallationWorker).not_to receive(:perform_in)
+
+ service.execute
+
+ expect(application).to be_installed
+ expect(application.status_reason).to be_nil
+ end
end
context 'when installation POD failed' do
diff --git a/spec/services/clusters/applications/finalize_installation_service_spec.rb b/spec/services/clusters/applications/finalize_installation_service_spec.rb
deleted file mode 100644
index 08b7a80dfcd..00000000000
--- a/spec/services/clusters/applications/finalize_installation_service_spec.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require 'spec_helper'
-
-describe Clusters::Applications::FinalizeInstallationService do
- describe '#execute' do
- let(:application) { create(:applications_helm, :installing) }
- let(:service) { described_class.new(application) }
-
- before do
- expect_any_instance_of(Gitlab::Kubernetes::Helm).to receive(:delete_installation_pod!).with(application)
- end
-
- context 'when installation POD succeeded' do
- it 'make the application installed' do
- service.execute
-
- expect(application).to be_installed
- expect(application.status_reason).to be_nil
- end
- end
-
- context 'when installation POD failed' do
- let(:application) { create(:applications_helm, :errored) }
-
- it 'make the application errored' do
- service.execute
-
- expect(application).to be_errored
- expect(application.status_reason).not_to be_nil
- end
- end
- end
-end
diff --git a/spec/services/clusters/applications/install_service_spec.rb b/spec/services/clusters/applications/install_service_spec.rb
index a646dac1cae..408f7e4354e 100644
--- a/spec/services/clusters/applications/install_service_spec.rb
+++ b/spec/services/clusters/applications/install_service_spec.rb
@@ -2,16 +2,22 @@ require 'spec_helper'
describe Clusters::Applications::InstallService do
describe '#execute' do
- let(:application) { create(:applications_helm, :scheduled) }
+ let(:application) { create(:cluster_applications_helm, :scheduled) }
let(:service) { described_class.new(application) }
+ let(:helm_client) { instance_double(Gitlab::Kubernetes::Helm) }
+
+ before do
+ allow(service).to receive(:helm_api).and_return(helm_client)
+ end
context 'when there are no errors' do
before do
- expect_any_instance_of(Gitlab::Kubernetes::Helm).to receive(:install).with(application)
+ expect(helm_client).to receive(:install).with(application)
allow(ClusterWaitForAppInstallationWorker).to receive(:perform_in).and_return(nil)
end
it 'make the application installing' do
+ expect(application.cluster).not_to be_nil
service.execute
expect(application).to be_installing
@@ -27,7 +33,7 @@ describe Clusters::Applications::InstallService do
context 'when k8s cluster communication fails' do
before do
error = KubeException.new(500, 'system failure', nil)
- expect_any_instance_of(Gitlab::Kubernetes::Helm).to receive(:install).with(application).and_raise(error)
+ expect(helm_client).to receive(:install).with(application).and_raise(error)
end
it 'make the application errored' do
@@ -39,11 +45,11 @@ describe Clusters::Applications::InstallService do
end
context 'when application cannot be persisted' do
- let(:application) { build(:applications_helm, :scheduled) }
+ let(:application) { build(:cluster_applications_helm, :scheduled) }
it 'make the application errored' do
expect(application).to receive(:make_installing!).once.and_raise(ActiveRecord::RecordInvalid)
- expect_any_instance_of(Gitlab::Kubernetes::Helm).not_to receive(:install)
+ expect(helm_client).not_to receive(:install)
service.execute
diff --git a/spec/services/clusters/applications/schedule_installation_service_spec.rb b/spec/services/clusters/applications/schedule_installation_service_spec.rb
index 6ba587a41db..cf95361c935 100644
--- a/spec/services/clusters/applications/schedule_installation_service_spec.rb
+++ b/spec/services/clusters/applications/schedule_installation_service_spec.rb
@@ -32,7 +32,7 @@ describe Clusters::Applications::ScheduleInstallationService do
end
context 'when installation is already in progress' do
- let(:application) { create(:applications_helm, :installing) }
+ let(:application) { create(:cluster_applications_helm, :installing) }
let(:cluster) { application.cluster }
it_behaves_like 'a failing service'