From 9065599e7947e44ea51be9824fe60b0d858b1605 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 19 Oct 2018 05:03:53 -0700 Subject: Add a spec that generates the metadata dynamically --- .../lib/gitlab/ci/build/artifacts/metadata_spec.rb | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'spec/lib/gitlab') diff --git a/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb b/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb index e327399d82d..a9a4af1f455 100644 --- a/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb +++ b/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb @@ -112,4 +112,34 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do end end end + + context 'generated metadata' do + let(:tmpfile) { Tempfile.new('test-metadata') } + let(:generator) { CiArtifactMetadataGenerator.new(tmpfile) } + let(:entry_count) { 5 } + + before do + tmpfile.binmode + + (1..entry_count).each do |index| + generator.add_entry("public/test-#{index}.txt") + end + + generator.write + end + + after do + File.unlink(tmpfile.path) + end + + describe '#find_entries!' do + it 'reads expected number of entries' do + stream = File.open(tmpfile.path) + + metadata = described_class.new(stream, 'public', { recursive: true }) + + expect(metadata.find_entries!.count).to eq entry_count + end + end + end end -- cgit v1.2.1 From bc333f38d82097288586d0847d6f8e31738e8575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Sun, 7 Oct 2018 10:22:40 +0200 Subject: Support licenses and performance This introduces a new syntax for all licenses and performance jobs: ```yaml job: reports: performance: performance.json license_management: gl-license-management-report.json ``` --- spec/lib/gitlab/ci/config/entry/reports_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/lib/gitlab') diff --git a/spec/lib/gitlab/ci/config/entry/reports_spec.rb b/spec/lib/gitlab/ci/config/entry/reports_spec.rb index 7cf541447ce..8095a231cf3 100644 --- a/spec/lib/gitlab/ci/config/entry/reports_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/reports_spec.rb @@ -38,6 +38,8 @@ describe Gitlab::Ci::Config::Entry::Reports do :dependency_scanning | 'gl-dependency-scanning-report.json' :container_scanning | 'gl-container-scanning-report.json' :dast | 'gl-dast-report.json' + :license_management | 'gl-license-management-report.json' + :performance | 'performance.json' end with_them do -- cgit v1.2.1 From be493207b069d832d5ecb97fb157df60fa58094f Mon Sep 17 00:00:00 2001 From: Cindy Pallares Date: Fri, 19 Oct 2018 11:36:41 -0500 Subject: Alias the lfs_enabled method We currently check for `project.lfs_enabled` to display the state of lfs being enabled/disabled, but this is set to nil by default, even when lfs is enabled. Aliasing the method to #lfs_enabled? will return the correct state. --- spec/lib/gitlab/import_export/project_tree_restorer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib/gitlab') diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index 7ebfc61f5e7..b0570680d5a 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -335,7 +335,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do restored_project_json - expect(project.lfs_enabled).to be_nil + expect(project.lfs_enabled).to be_falsey end end -- cgit v1.2.1 From 1e4d61500039ad84e2ab95b58910f592994f56e5 Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Mon, 22 Oct 2018 16:47:54 -0500 Subject: Add RoleBinding methods Includes RoleBinding methods to Kubeclient and introduce a new lib class to generate RoleBinding resources. This MR is part of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/22011 --- spec/lib/gitlab/kubernetes/role_binding_spec.rb | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 spec/lib/gitlab/kubernetes/role_binding_spec.rb (limited to 'spec/lib/gitlab') diff --git a/spec/lib/gitlab/kubernetes/role_binding_spec.rb b/spec/lib/gitlab/kubernetes/role_binding_spec.rb new file mode 100644 index 00000000000..da3f5d27b25 --- /dev/null +++ b/spec/lib/gitlab/kubernetes/role_binding_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Kubernetes::RoleBinding, '#generate' do + let(:role_name) { 'edit' } + let(:namespace) { 'my-namespace' } + let(:service_account_name) { 'my-service-account' } + + let(:subjects) do + [ + { + kind: 'ServiceAccount', + name: service_account_name, + namespace: namespace + } + ] + end + + let(:role_ref) do + { + apiGroup: 'rbac.authorization.k8s.io', + kind: 'Role', + name: role_name + } + end + + let(:resource) do + ::Kubeclient::Resource.new( + metadata: { name: "gitlab-#{namespace}", namespace: namespace }, + roleRef: role_ref, + subjects: subjects + ) + end + + subject do + described_class.new( + role_name: role_name, + namespace: namespace, + service_account_name: service_account_name + ).generate + end + + it 'should build a Kubeclient Resource' do + is_expected.to eq(resource) + end +end -- cgit v1.2.1 From 983c4a50d083be8e9a980613d98937a587450b18 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Wed, 3 Oct 2018 15:36:00 +1300 Subject: Remove api_groups from KubeClient constructor We should have access to #core_client, #rbac_client, and #extensions_client without having to pass in an awkward array. Also change api_version to default_api_version, which allows us to use a different version for an individual client. Special case for apis/extensions which only go up to v1beta1 Makes #hashed_client private Removes the #clients and #discover! methods which are un-used --- spec/lib/gitlab/kubernetes/kube_client_spec.rb | 129 ++++++++----------------- 1 file changed, 39 insertions(+), 90 deletions(-) (limited to 'spec/lib/gitlab') diff --git a/spec/lib/gitlab/kubernetes/kube_client_spec.rb b/spec/lib/gitlab/kubernetes/kube_client_spec.rb index 53c5a4e7c94..ba38e2c31ea 100644 --- a/spec/lib/gitlab/kubernetes/kube_client_spec.rb +++ b/spec/lib/gitlab/kubernetes/kube_client_spec.rb @@ -6,103 +6,87 @@ describe Gitlab::Kubernetes::KubeClient do include KubernetesHelpers let(:api_url) { 'https://kubernetes.example.com/prefix' } - let(:api_groups) { ['api', 'apis/rbac.authorization.k8s.io'] } let(:api_version) { 'v1' } let(:kubeclient_options) { { auth_options: { bearer_token: 'xyz' } } } - let(:client) { described_class.new(api_url, api_groups, api_version, kubeclient_options) } + let(:client) { described_class.new(api_url, api_version, kubeclient_options) } before do stub_kubeclient_discover(api_url) end - describe '#hashed_clients' do - subject { client.hashed_clients } - - it 'has keys from api groups' do - expect(subject.keys).to match_array api_groups + shared_examples 'a Kubeclient' do + it 'is a Kubeclient::Client' do + is_expected.to be_an_instance_of Kubeclient::Client end - it 'has values of Kubeclient::Client' do - expect(subject.values).to all(be_an_instance_of Kubeclient::Client) + it 'has the kubeclient options' do + expect(subject.auth_options).to eq({ bearer_token: 'xyz' }) end end - describe '#clients' do - subject { client.clients } - - it 'is not empty' do - is_expected.to be_present - end - - it 'is an array of Kubeclient::Client objects' do - is_expected.to all(be_an_instance_of Kubeclient::Client) - end - - it 'has each API group url' do - expected_urls = api_groups.map { |group| "#{api_url}/#{group}" } + describe '#core_client' do + subject { client.core_client } - expect(subject.map(&:api_endpoint).map(&:to_s)).to match_array(expected_urls) - end + it_behaves_like 'a Kubeclient' - it 'has the kubeclient options' do - subject.each do |client| - expect(client.auth_options).to eq({ bearer_token: 'xyz' }) - end + it 'has the core API endpoint' do + expect(subject.api_endpoint.to_s).to match(%r{\/api\Z}) end it 'has the api_version' do - subject.each do |client| - expect(client.instance_variable_get(:@api_version)).to eq('v1') - end + expect(subject.instance_variable_get(:@api_version)).to eq('v1') end - end - - describe '#core_client' do - subject { client.core_client } - it 'is a Kubeclient::Client' do - is_expected.to be_an_instance_of Kubeclient::Client - end + context 'different api version' do + subject { client.core_client(api_version: 'v2') } - it 'has the core API endpoint' do - expect(subject.api_endpoint.to_s).to match(%r{\/api\Z}) + it 'has the api_version' do + expect(subject.instance_variable_get(:@api_version)).to eq('v2') + end end end describe '#rbac_client' do subject { client.rbac_client } - it 'is a Kubeclient::Client' do - is_expected.to be_an_instance_of Kubeclient::Client - end + it_behaves_like 'a Kubeclient' it 'has the RBAC API group endpoint' do expect(subject.api_endpoint.to_s).to match(%r{\/apis\/rbac.authorization.k8s.io\Z}) end + + it 'has the api_version' do + expect(subject.instance_variable_get(:@api_version)).to eq('v1') + end + + context 'different api version' do + subject { client.rbac_client(api_version: 'v2') } + + it 'has the api_version' do + expect(subject.instance_variable_get(:@api_version)).to eq('v2') + end + end end describe '#extensions_client' do subject { client.extensions_client } - let(:api_groups) { ['apis/extensions'] } - - it 'is a Kubeclient::Client' do - is_expected.to be_an_instance_of Kubeclient::Client - end + it_behaves_like 'a Kubeclient' it 'has the extensions API group endpoint' do expect(subject.api_endpoint.to_s).to match(%r{\/apis\/extensions\Z}) end - end - describe '#discover!' do - it 'makes a discovery request for each API group' do - client.discover! + it 'has the api_version' do + expect(subject.instance_variable_get(:@api_version)).to eq('v1beta1') + end - api_groups.each do |api_group| - discovery_url = api_url + '/' + api_group + '/v1' - expect(WebMock).to have_requested(:get, discovery_url).once + context 'different api version' do + subject { client.extensions_client(api_version: 'v2') } + + it 'has the api_version' do + expect(subject.instance_variable_get(:@api_version)).to eq('v2') end end end @@ -156,14 +140,6 @@ describe Gitlab::Kubernetes::KubeClient do it 'responds to the method' do expect(client).to respond_to method end - - context 'no rbac client' do - let(:api_groups) { ['api'] } - - it 'throws an error' do - expect { client.public_send(method) }.to raise_error(Module::DelegationError) - end - end end end end @@ -181,22 +157,11 @@ describe Gitlab::Kubernetes::KubeClient do it 'responds to the method' do expect(client).to respond_to :get_deployments end - - context 'no extensions client' do - let(:api_groups) { ['api'] } - let(:api_version) { 'v1' } - - it 'throws an error' do - expect { client.get_deployments }.to raise_error(Module::DelegationError) - end - end end end describe 'non-entity methods' do it 'does not proxy for non-entity methods' do - expect(client.clients.first).to respond_to :proxy_url - expect(client).not_to respond_to :proxy_url end @@ -211,14 +176,6 @@ describe Gitlab::Kubernetes::KubeClient do it 'is delegated to the core client' do expect(client).to delegate_method(:get_pod_log).to(:core_client) end - - context 'when no core client' do - let(:api_groups) { ['apis/extensions'] } - - it 'throws an error' do - expect { client.get_pod_log('pod-name') }.to raise_error(Module::DelegationError) - end - end end describe '#watch_pod_log' do @@ -227,14 +184,6 @@ describe Gitlab::Kubernetes::KubeClient do it 'is delegated to the core client' do expect(client).to delegate_method(:watch_pod_log).to(:core_client) end - - context 'when no core client' do - let(:api_groups) { ['apis/extensions'] } - - it 'throws an error' do - expect { client.watch_pod_log('pod-name') }.to raise_error(Module::DelegationError) - end - end end describe 'methods that do not exist on any client' do -- cgit v1.2.1 From a5419138fd1dd766713a3754c8406133b3d9b99b Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Tue, 23 Oct 2018 23:52:34 +1300 Subject: Store version within SUPPORTED_API_GROUPS hash This removes the ability to pass in a different version. We can instead create a new entry in the SUPPORTED_API_GROUPS hash for a different version if need be. --- spec/lib/gitlab/kubernetes/kube_client_spec.rb | 28 +------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) (limited to 'spec/lib/gitlab') diff --git a/spec/lib/gitlab/kubernetes/kube_client_spec.rb b/spec/lib/gitlab/kubernetes/kube_client_spec.rb index ba38e2c31ea..eed4135d8a2 100644 --- a/spec/lib/gitlab/kubernetes/kube_client_spec.rb +++ b/spec/lib/gitlab/kubernetes/kube_client_spec.rb @@ -6,10 +6,9 @@ describe Gitlab::Kubernetes::KubeClient do include KubernetesHelpers let(:api_url) { 'https://kubernetes.example.com/prefix' } - let(:api_version) { 'v1' } let(:kubeclient_options) { { auth_options: { bearer_token: 'xyz' } } } - let(:client) { described_class.new(api_url, api_version, kubeclient_options) } + let(:client) { described_class.new(api_url, kubeclient_options) } before do stub_kubeclient_discover(api_url) @@ -37,14 +36,6 @@ describe Gitlab::Kubernetes::KubeClient do it 'has the api_version' do expect(subject.instance_variable_get(:@api_version)).to eq('v1') end - - context 'different api version' do - subject { client.core_client(api_version: 'v2') } - - it 'has the api_version' do - expect(subject.instance_variable_get(:@api_version)).to eq('v2') - end - end end describe '#rbac_client' do @@ -59,14 +50,6 @@ describe Gitlab::Kubernetes::KubeClient do it 'has the api_version' do expect(subject.instance_variable_get(:@api_version)).to eq('v1') end - - context 'different api version' do - subject { client.rbac_client(api_version: 'v2') } - - it 'has the api_version' do - expect(subject.instance_variable_get(:@api_version)).to eq('v2') - end - end end describe '#extensions_client' do @@ -81,14 +64,6 @@ describe Gitlab::Kubernetes::KubeClient do it 'has the api_version' do expect(subject.instance_variable_get(:@api_version)).to eq('v1beta1') end - - context 'different api version' do - subject { client.extensions_client(api_version: 'v2') } - - it 'has the api_version' do - expect(subject.instance_variable_get(:@api_version)).to eq('v2') - end - end end describe 'core API' do @@ -146,7 +121,6 @@ describe Gitlab::Kubernetes::KubeClient do describe 'extensions API group' do let(:api_groups) { ['apis/extensions'] } - let(:api_version) { 'v1beta1' } let(:extensions_client) { client.extensions_client } describe '#get_deployments' do -- cgit v1.2.1