diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 06:09:38 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 06:09:38 +0000 |
commit | ed9165c2abda1dca048a8d3cb8030d906c0bbb0c (patch) | |
tree | 226d7ad6b9abdc8d2534c3025b488ce9a754dee6 /spec | |
parent | b4b9b3854eddd2a4829113ebfc1812c3a332a7d9 (diff) | |
download | gitlab-ce-ed9165c2abda1dca048a8d3cb8030d906c0bbb0c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
5 files changed, 75 insertions, 120 deletions
diff --git a/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js b/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js index 8c3525207d6..c1ac3841136 100644 --- a/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js +++ b/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js @@ -1,16 +1,18 @@ import testAction from 'helpers/vuex_action_helper'; +import createState from '~/create_cluster/gke_cluster/store/state'; +import * as types from '~/create_cluster/gke_cluster/store/mutation_types'; import * as actions from '~/create_cluster/gke_cluster/store/actions'; -import { createStore } from '~/create_cluster/gke_cluster/store'; import gapi from '../helpers'; -import { selectedProjectMock, selectedZoneMock, selectedMachineTypeMock } from '../mock_data'; +import { + selectedProjectMock, + selectedZoneMock, + selectedMachineTypeMock, + gapiProjectsResponseMock, + gapiZonesResponseMock, + gapiMachineTypesResponseMock, +} from '../mock_data'; describe('GCP Cluster Dropdown Store Actions', () => { - let store; - - beforeEach(() => { - store = createStore(); - }); - describe('setProject', () => { it('should set project', done => { testAction( @@ -76,16 +78,16 @@ describe('GCP Cluster Dropdown Store Actions', () => { }); describe('fetchProjects', () => { - it('fetches projects from Google API', done => { - store - .dispatch('fetchProjects') - .then(() => { - expect(store.state.projects[0].projectId).toEqual(selectedProjectMock.projectId); - expect(store.state.projects[0].name).toEqual(selectedProjectMock.name); - - done(); - }) - .catch(done.fail); + it('fetches projects from Google API', () => { + const state = createState(); + + return testAction( + actions.fetchProjects, + null, + state, + [{ type: types.SET_PROJECTS, payload: gapiProjectsResponseMock.projects }], + [], + ); }); }); @@ -112,28 +114,30 @@ describe('GCP Cluster Dropdown Store Actions', () => { }); describe('fetchZones', () => { - it('fetches zones from Google API', done => { - store - .dispatch('fetchZones') - .then(() => { - expect(store.state.zones[0].name).toEqual(selectedZoneMock); - - done(); - }) - .catch(done.fail); + it('fetches zones from Google API', () => { + const state = createState(); + + return testAction( + actions.fetchZones, + null, + state, + [{ type: types.SET_ZONES, payload: gapiZonesResponseMock.items }], + [], + ); }); }); describe('fetchMachineTypes', () => { - it('fetches machine types from Google API', done => { - store - .dispatch('fetchMachineTypes') - .then(() => { - expect(store.state.machineTypes[0].name).toEqual(selectedMachineTypeMock); - - done(); - }) - .catch(done.fail); + it('fetches machine types from Google API', () => { + const state = createState(); + + return testAction( + actions.fetchMachineTypes, + null, + state, + [{ type: types.SET_MACHINE_TYPES, payload: gapiMachineTypesResponseMock.items }], + [], + ); }); }); }); diff --git a/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js b/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js index 7ee6ff436e2..2a742b6ed8f 100644 --- a/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js +++ b/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js @@ -1,87 +1,32 @@ -import { createStore } from '~/create_cluster/gke_cluster/store'; +import createState from '~/create_cluster/gke_cluster/store/state'; import * as types from '~/create_cluster/gke_cluster/store/mutation_types'; +import mutations from '~/create_cluster/gke_cluster/store/mutations'; import { - selectedProjectMock, - selectedZoneMock, - selectedMachineTypeMock, gapiProjectsResponseMock, gapiZonesResponseMock, gapiMachineTypesResponseMock, } from '../mock_data'; describe('GCP Cluster Dropdown Store Mutations', () => { - let store; - - beforeEach(() => { - store = createStore(); - }); - - describe('SET_PROJECT', () => { - it('should set GCP project as selectedProject', () => { - const projectToSelect = gapiProjectsResponseMock.projects[0]; - - store.commit(types.SET_PROJECT, projectToSelect); - - expect(store.state.selectedProject.projectId).toEqual(selectedProjectMock.projectId); - expect(store.state.selectedProject.name).toEqual(selectedProjectMock.name); - }); - }); - - describe('SET_PROJECT_BILLING_STATUS', () => { - it('should set project billing status', () => { - store.commit(types.SET_PROJECT_BILLING_STATUS, true); - - expect(store.state.projectHasBillingEnabled).toBeTruthy(); - }); - }); - - describe('SET_ZONE', () => { - it('should set GCP zone as selectedZone', () => { - const zoneToSelect = gapiZonesResponseMock.items[0].name; - - store.commit(types.SET_ZONE, zoneToSelect); - - expect(store.state.selectedZone).toEqual(selectedZoneMock); - }); - }); - - describe('SET_MACHINE_TYPE', () => { - it('should set GCP machine type as selectedMachineType', () => { - const machineTypeToSelect = gapiMachineTypesResponseMock.items[0].name; - - store.commit(types.SET_MACHINE_TYPE, machineTypeToSelect); - - expect(store.state.selectedMachineType).toEqual(selectedMachineTypeMock); - }); - }); - - describe('SET_PROJECTS', () => { - it('should set Google API Projects response as projects', () => { - expect(store.state.projects.length).toEqual(0); - - store.commit(types.SET_PROJECTS, gapiProjectsResponseMock.projects); - - expect(store.state.projects.length).toEqual(gapiProjectsResponseMock.projects.length); - }); - }); - - describe('SET_ZONES', () => { - it('should set Google API Zones response as zones', () => { - expect(store.state.zones.length).toEqual(0); - - store.commit(types.SET_ZONES, gapiZonesResponseMock.items); - - expect(store.state.zones.length).toEqual(gapiZonesResponseMock.items.length); - }); - }); - - describe('SET_MACHINE_TYPES', () => { - it('should set Google API Machine Types response as machineTypes', () => { - expect(store.state.machineTypes.length).toEqual(0); - - store.commit(types.SET_MACHINE_TYPES, gapiMachineTypesResponseMock.items); - - expect(store.state.machineTypes.length).toEqual(gapiMachineTypesResponseMock.items.length); + describe.each` + mutation | stateProperty | mockData + ${types.SET_PROJECTS} | ${'projects'} | ${gapiProjectsResponseMock.projects} + ${types.SET_ZONES} | ${'zones'} | ${gapiZonesResponseMock.items} + ${types.SET_MACHINE_TYPES} | ${'machineTypes'} | ${gapiMachineTypesResponseMock.items} + ${types.SET_MACHINE_TYPE} | ${'selectedMachineType'} | ${gapiMachineTypesResponseMock.items[0].name} + ${types.SET_ZONE} | ${'selectedZone'} | ${gapiZonesResponseMock.items[0].name} + ${types.SET_PROJECT} | ${'selectedProject'} | ${gapiProjectsResponseMock.projects[0]} + ${types.SET_PROJECT_BILLING_STATUS} | ${'projectHasBillingEnabled'} | ${true} + ${types.SET_IS_VALIDATING_PROJECT_BILLING} | ${'isValidatingProjectBilling'} | ${true} + `('$mutation', ({ mutation, stateProperty, mockData }) => { + it(`should set the mutation payload to the ${stateProperty} state property`, () => { + const state = createState(); + + expect(state[stateProperty]).not.toBe(mockData); + + mutations[mutation](state, mockData); + + expect(state[stateProperty]).toBe(mockData); }); }); }); diff --git a/spec/services/pod_logs/base_service_spec.rb b/spec/services/pod_logs/base_service_spec.rb index d93ea51eae1..fb53321352b 100644 --- a/spec/services/pod_logs/base_service_spec.rb +++ b/spec/services/pod_logs/base_service_spec.rb @@ -9,11 +9,13 @@ describe ::PodLogs::BaseService do let(:namespace) { 'autodevops-deploy-9-production' } let(:pod_name) { 'pod-1' } + let(:pod_name_2) { 'pod-2' } let(:container_name) { 'container-0' } let(:params) { {} } let(:raw_pods) do JSON.parse([ - kube_pod(name: pod_name) + kube_pod(name: pod_name), + kube_pod(name: pod_name_2) ].to_json, object_class: OpenStruct) end @@ -115,7 +117,7 @@ describe ::PodLogs::BaseService do result = subject.send(:get_pod_names, raw_pods: raw_pods) expect(result[:status]).to eq(:success) - expect(result[:pods]).to eq([pod_name]) + expect(result[:pods]).to eq([pod_name, pod_name_2]) end end end diff --git a/spec/services/pod_logs/kubernetes_service_spec.rb b/spec/services/pod_logs/kubernetes_service_spec.rb index 8ce79d4c318..ff0554bbe5c 100644 --- a/spec/services/pod_logs/kubernetes_service_spec.rb +++ b/spec/services/pod_logs/kubernetes_service_spec.rb @@ -9,16 +9,20 @@ describe ::PodLogs::KubernetesService do let(:namespace) { 'autodevops-deploy-9-production' } let(:pod_name) { 'pod-1' } + let(:pod_name_2) { 'pod-2' } let(:container_name) { 'container-0' } + let(:container_name_2) { 'foo-0' } let(:params) { {} } let(:raw_logs) do "2019-12-13T14:04:22.123456Z Log 1\n2019-12-13T14:04:23.123456Z Log 2\n" \ "2019-12-13T14:04:24.123456Z Log 3" end + let(:raw_pods) do JSON.parse([ - kube_pod(name: pod_name) + kube_pod(name: pod_name), + kube_pod(name: pod_name_2, container_name: container_name_2) ].to_json, object_class: OpenStruct) end @@ -220,12 +224,12 @@ describe ::PodLogs::KubernetesService do it 'returns success if container_name was not specified and there are containers' do result = subject.send(:check_container_name, - pod_name: pod_name, + pod_name: pod_name_2, raw_pods: raw_pods ) expect(result[:status]).to eq(:success) - expect(result[:container_name]).to eq(container_name) + expect(result[:container_name]).to eq(container_name_2) end it 'returns error if container_name was not specified and there are no containers on the pod' do diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index 427948bda96..ca910e47695 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -489,7 +489,7 @@ module KubernetesHelpers # This is a partial response, it will have many more elements in reality but # these are the ones we care about at the moment - def kube_pod(name: "kube-pod", environment_slug: "production", namespace: "project-namespace", project_slug: "project-path-slug", status: "Running", track: nil) + def kube_pod(name: "kube-pod", container_name: "container-0", environment_slug: "production", namespace: "project-namespace", project_slug: "project-path-slug", status: "Running", track: nil) { "metadata" => { "name" => name, @@ -506,8 +506,8 @@ module KubernetesHelpers }, "spec" => { "containers" => [ - { "name" => "container-0" }, - { "name" => "container-1" } + { "name" => "#{container_name}" }, + { "name" => "#{container_name}-1" } ] }, "status" => { "phase" => status } |