jupyter_spec.rb 3.3 KB
Newer Older
1 2 3 4
require 'rails_helper'

describe Clusters::Applications::Jupyter do
  include_examples 'cluster application core specs', :clusters_applications_jupyter
5
  include_examples 'cluster application helm specs', :clusters_applications_jupyter
6 7 8 9 10 11 12 13 14 15 16 17

  it { is_expected.to belong_to(:oauth_application) }

  describe '#set_initial_status' do
    before do
      jupyter.set_initial_status
    end

    context 'when ingress is not installed' do
      let(:cluster) { create(:cluster, :provided_by_gcp) }
      let(:jupyter) { create(:clusters_applications_jupyter, cluster: cluster) }

18
      it { expect(jupyter).to be_not_installable }
19 20 21 22 23 24
    end

    context 'when ingress is installed and external_ip is assigned' do
      let(:ingress) { create(:clusters_applications_ingress, :installed, external_ip: '127.0.0.1') }
      let(:jupyter) { create(:clusters_applications_jupyter, cluster: ingress.cluster) }

25
      it { expect(jupyter).to be_installable }
26 27 28
    end
  end

29 30 31 32 33 34 35 36 37 38 39 40 41 42
  describe '#make_installing!' do
    before do
      application.make_installing!
    end

    context 'application install previously errored with older version' do
      let(:application) { create(:clusters_applications_jupyter, :scheduled, version: 'v0.5') }

      it 'updates the application version' do
        expect(application.reload.version).to eq('v0.6')
      end
    end
  end

43 44 45 46 47 48 49 50 51 52 53
  describe '#install_command' do
    let!(:ingress) { create(:clusters_applications_ingress, :installed, external_ip: '127.0.0.1') }
    let!(:jupyter) { create(:clusters_applications_jupyter, cluster: ingress.cluster) }

    subject { jupyter.install_command }

    it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) }

    it 'should be initialized with 4 arguments' do
      expect(subject.name).to eq('jupyter')
      expect(subject.chart).to eq('jupyter/jupyterhub')
54
      expect(subject.version).to eq('v0.6')
55
      expect(subject).to be_rbac
56
      expect(subject.repository).to eq('https://jupyterhub.github.io/helm-chart/')
57
      expect(subject.files).to eq(jupyter.files)
58
    end
59

60
    context 'on a non rbac enabled cluster' do
61
      before do
62
        jupyter.cluster.platform_kubernetes.abac!
63 64
      end

65
      it { is_expected.not_to be_rbac }
66 67
    end

68 69 70 71 72 73 74
    context 'application failed to install previously' do
      let(:jupyter) { create(:clusters_applications_jupyter, :errored, version: '0.0.1') }

      it 'should be initialized with the locked version' do
        expect(subject.version).to eq('v0.6')
      end
    end
75 76
  end

77 78 79
  describe '#files' do
    let(:application) { create(:clusters_applications_jupyter) }
    let(:values) { subject[:'values.yaml'] }
80

81 82
    subject { application.files }

83
    it 'should include valid values' do
84 85 86 87 88
      expect(values).to include('ingress')
      expect(values).to include('hub')
      expect(values).to include('rbac')
      expect(values).to include('proxy')
      expect(values).to include('auth')
89
      expect(values).to include('singleuser')
90 91
      expect(values).to match(/clientId: '?#{application.oauth_application.uid}/)
      expect(values).to match(/callbackUrl: '?#{application.callback_url}/)
92
    end
93 94 95 96 97 98

    context 'when cluster belongs to a project' do
      it 'sets GitLab project id' do
        expect(values).to match(/GITLAB_CLUSTER_ID: '?#{application.cluster.id}/)
      end
    end
99 100
  end
end