summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
authorDJ Mountney <david@twkie.net>2018-10-25 08:48:14 -0700
committerDJ Mountney <david@twkie.net>2018-10-25 08:48:14 -0700
commitfee6989fa003395a6188f8ca452adab25d8ece6b (patch)
treeb18aa69513c0158a5e71f5d3479b1dba0cb2c00a /spec/lib/gitlab
parent34d84fd29fe346dbf95a0cf76de803b6e61c45c6 (diff)
parent4de9004175e7c1dfd0366c41d70573d4d686b292 (diff)
downloadgitlab-ce-fee6989fa003395a6188f8ca452adab25d8ece6b.tar.gz
Merge remote-tracking branch 'origin/master' into dev-master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb30
-rw-r--r--spec/lib/gitlab/ci/config/entry/reports_spec.rb2
-rw-r--r--spec/lib/gitlab/import_export/project_tree_restorer_spec.rb2
-rw-r--r--spec/lib/gitlab/kubernetes/kube_client_spec.rb113
-rw-r--r--spec/lib/gitlab/kubernetes/role_binding_spec.rb47
5 files changed, 98 insertions, 96 deletions
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
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
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
diff --git a/spec/lib/gitlab/kubernetes/kube_client_spec.rb b/spec/lib/gitlab/kubernetes/kube_client_spec.rb
index 53c5a4e7c94..eed4135d8a2 100644
--- a/spec/lib/gitlab/kubernetes/kube_client_spec.rb
+++ b/spec/lib/gitlab/kubernetes/kube_client_spec.rb
@@ -6,104 +6,63 @@ 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, 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
- end
-
- it 'has values of Kubeclient::Client' do
- expect(subject.values).to all(be_an_instance_of Kubeclient::Client)
- 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}" }
-
- expect(subject.map(&:api_endpoint).map(&:to_s)).to match_array(expected_urls)
+ shared_examples 'a Kubeclient' do
+ it 'is a Kubeclient::Client' do
+ is_expected.to be_an_instance_of Kubeclient::Client
end
it 'has the kubeclient options' do
- subject.each do |client|
- expect(client.auth_options).to eq({ bearer_token: 'xyz' })
- end
- end
-
- it 'has the api_version' do
- subject.each do |client|
- expect(client.instance_variable_get(:@api_version)).to eq('v1')
- end
+ expect(subject.auth_options).to eq({ bearer_token: 'xyz' })
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
+ it_behaves_like 'a Kubeclient'
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
+ expect(subject.instance_variable_get(:@api_version)).to eq('v1')
+ 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
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!
-
- api_groups.each do |api_group|
- discovery_url = api_url + '/' + api_group + '/v1'
- expect(WebMock).to have_requested(:get, discovery_url).once
- end
+ it 'has the api_version' do
+ expect(subject.instance_variable_get(:@api_version)).to eq('v1beta1')
end
end
@@ -156,21 +115,12 @@ 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
describe 'extensions API group' do
let(:api_groups) { ['apis/extensions'] }
- let(:api_version) { 'v1beta1' }
let(:extensions_client) { client.extensions_client }
describe '#get_deployments' do
@@ -181,22 +131,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 +150,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 +158,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
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