Commit 97b2ec92 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents bf9c14de 1cc51c95
...@@ -279,7 +279,7 @@ export default { ...@@ -279,7 +279,7 @@ export default {
<div class="pipelines-container"> <div class="pipelines-container">
<div <div
v-if="shouldRenderTabs || shouldRenderButtons" v-if="shouldRenderTabs || shouldRenderButtons"
class="top-area scrolling-tabs-container inner-page-scroll-tabs" class="top-area scrolling-tabs-container inner-page-scroll-tabs gl-border-none"
> >
<div class="fade-left"><gl-icon name="chevron-lg-left" :size="12" /></div> <div class="fade-left"><gl-icon name="chevron-lg-left" :size="12" /></div>
<div class="fade-right"><gl-icon name="chevron-lg-right" :size="12" /></div> <div class="fade-right"><gl-icon name="chevron-lg-right" :size="12" /></div>
......
<script> <script>
import $ from 'jquery'; import $ from 'jquery';
import { GlBadge, GlTabs, GlTab } from '@gitlab/ui';
/** /**
* Given an array of tabs, renders non linked bootstrap tabs. * Given an array of tabs, renders non linked bootstrap tabs.
...@@ -23,6 +24,11 @@ import $ from 'jquery'; ...@@ -23,6 +24,11 @@ import $ from 'jquery';
*/ */
export default { export default {
name: 'NavigationTabs', name: 'NavigationTabs',
components: {
GlBadge,
GlTabs,
GlTab,
},
props: { props: {
tabs: { tabs: {
type: Array, type: Array,
...@@ -50,24 +56,21 @@ export default { ...@@ -50,24 +56,21 @@ export default {
}; };
</script> </script>
<template> <template>
<ul class="nav-links scrolling-tabs separator"> <gl-tabs class="gl-display-flex gl-w-full" nav-class="gl-border-0!">
<li <gl-tab
v-for="(tab, i) in tabs" v-for="(tab, i) in tabs"
:key="i" :key="i"
:class="{ :title-link-class="`js-${scope}-tab-${tab.scope} gl-display-inline-flex`"
active: tab.isActive, :title-link-attributes="{ 'data-testid': `${scope}-tab-${tab.scope}` }"
}" :active="tab.isActive"
@click="onTabClick(tab)"
> >
<a <template #title>
:class="`js-${scope}-tab-${tab.scope}`" <span class="gl-mr-2"> {{ tab.name }} </span>
:data-testid="`${scope}-tab-${tab.scope}`" <gl-badge v-if="shouldRenderBadge(tab.count)" size="sm" class="gl-tab-counter-badge">{{
role="button" tab.count
@click="onTabClick(tab)" }}</gl-badge>
> </template>
{{ tab.name }} </gl-tab>
</gl-tabs>
<span v-if="shouldRenderBadge(tab.count)" class="badge badge-pill"> {{ tab.count }} </span>
</a>
</li>
</ul>
</template> </template>
---
title: Convert navigation_tabs.vue to gl-tabs
merge_request: 47841
author:
type: other
...@@ -29,8 +29,8 @@ Docker image with the fuzz engine to run your app. ...@@ -29,8 +29,8 @@ Docker image with the fuzz engine to run your app.
| GoLang | [go-fuzz (libFuzzer support)](https://github.com/dvyukov/go-fuzz) | [go-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/go-fuzzing-example) | | GoLang | [go-fuzz (libFuzzer support)](https://github.com/dvyukov/go-fuzz) | [go-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/go-fuzzing-example) |
| Swift | [libfuzzer](https://github.com/apple/swift/blob/master/docs/libFuzzerIntegration.md) | [swift-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/swift-fuzzing-example) | | Swift | [libfuzzer](https://github.com/apple/swift/blob/master/docs/libFuzzerIntegration.md) | [swift-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/swift-fuzzing-example) |
| Rust | [cargo-fuzz (libFuzzer support)](https://github.com/rust-fuzz/cargo-fuzz) | [rust-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/rust-fuzzing-example) | | Rust | [cargo-fuzz (libFuzzer support)](https://github.com/rust-fuzz/cargo-fuzz) | [rust-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/rust-fuzzing-example) |
| Java | [JQF](https://github.com/rohanpadhye/JQF) | [java-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/java-fuzzing-example) |
| Java | [javafuzz](https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/javafuzz) (recommended) | [javafuzz-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/javafuzz-fuzzing-example) | | Java | [javafuzz](https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/javafuzz) (recommended) | [javafuzz-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/javafuzz-fuzzing-example) |
| Java | [JQF](https://github.com/rohanpadhye/JQF) (not preferred) | [jqf-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/java-fuzzing-example) |
| JavaScript | [jsfuzz](https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz)| [jsfuzz-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/jsfuzz-fuzzing-example) | | JavaScript | [jsfuzz](https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz)| [jsfuzz-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/jsfuzz-fuzzing-example) |
| Python | [pythonfuzz](https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/pythonfuzz)| [pythonfuzz-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/pythonfuzz-fuzzing-example) | | Python | [pythonfuzz](https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/pythonfuzz)| [pythonfuzz-fuzzing-example](https://gitlab.com/gitlab-org/security-products/demos/coverage-fuzzing/pythonfuzz-fuzzing-example) |
......
...@@ -13,7 +13,7 @@ module Geo ...@@ -13,7 +13,7 @@ module Geo
end end
def handle_after_create_commit def handle_after_create_commit
return false unless Gitlab::Geo.enabled? return false unless Gitlab::Geo.primary?
return unless self.class.enabled? return unless self.class.enabled?
publish(:created, **created_params) publish(:created, **created_params)
......
...@@ -125,17 +125,12 @@ module Geo ...@@ -125,17 +125,12 @@ module Geo
Geo::VerificationWorker.perform_async(replicable_name, model_record.id) Geo::VerificationWorker.perform_async(replicable_name, model_record.id)
end end
# Calculates checksum and asks the model/registry to update verification # Calculates checksum and asks the model/registry to manage verification
# state. # state.
def verify def verify
model_record.verification_started! unless model_record.verification_started? model_record.track_checksum_attempt! do
model_record.calculate_checksum
calculation_started_at = Time.current end
checksum = model_record.calculate_checksum
model_record.verification_succeeded_with_checksum!(checksum, calculation_started_at)
rescue => e
model_record.verification_failed_with_message!('Error calculating the checksum', e)
end end
# Check if given checksum matches known one # Check if given checksum matches known one
......
...@@ -267,14 +267,14 @@ module Gitlab ...@@ -267,14 +267,14 @@ module Gitlab
end end
def handle_after_destroy def handle_after_destroy
return false unless Gitlab::Geo.enabled? return false unless Gitlab::Geo.primary?
return unless self.class.enabled? return unless self.class.enabled?
publish(:deleted, **deleted_params) publish(:deleted, **deleted_params)
end end
def handle_after_update def handle_after_update
return false unless Gitlab::Geo.enabled? return false unless Gitlab::Geo.primary?
return unless self.class.enabled? return unless self.class.enabled?
publish(:updated, **updated_params) publish(:updated, **updated_params)
......
...@@ -177,6 +177,25 @@ module Gitlab ...@@ -177,6 +177,25 @@ module Gitlab
end end
end end
# Provides a safe and easy way to manage the verification state for a
# synchronous checksum calculation.
#
# @yieldreturn [String] calculated checksum value
def track_checksum_attempt!(&block)
# This line only applies to Geo::VerificationWorker, not
# Geo::VerificationBatchWorker, since the latter sets the whole batch to
# "verification_started" in the same DB query that fetches the batch.
verification_started! unless verification_started?
calculation_started_at = Time.current
checksum = yield
track_checksum_result!(checksum, calculation_started_at)
rescue => e
verification_failed_with_message!('Error during verification', e)
end
# Convenience method to update checksum and transition to success state. # Convenience method to update checksum and transition to success state.
# #
# @param [String] checksum value generated by the checksum routine # @param [String] checksum value generated by the checksum routine
...@@ -193,23 +212,36 @@ module Gitlab ...@@ -193,23 +212,36 @@ module Gitlab
end end
end end
def resource_updated_during_checksum?(calculation_started_at)
self.reset.verification_started_at > calculation_started_at
end
# Convenience method to update failure message and transition to failed # Convenience method to update failure message and transition to failed
# state. # state.
# #
# @param [String] message error information # @param [String] message error information
# @param [StandardError] error exception # @param [StandardError] error exception
def verification_failed_with_message!(message, error = nil) def verification_failed_with_message!(message, error = nil)
log_error('Error calculating the checksum', error) log_error(message, error)
self.verification_failure = message self.verification_failure = message
self.verification_failure += ": #{error.message}" if error.respond_to?(:message) self.verification_failure += ": #{error.message}" if error.respond_to?(:message)
self.verification_failed! self.verification_failed!
end end
private
# Records the calculated checksum result
#
# Overridden by ReplicableRegistry so it can also compare with primary
# checksum.
#
# @param [String] calculated checksum value
# @param [Time] when checksum calculation was started
def track_checksum_result!(checksum, calculation_started_at)
verification_succeeded_with_checksum!(checksum, calculation_started_at)
end
def resource_updated_during_checksum?(calculation_started_at)
self.reset.verification_started_at > calculation_started_at
end
end end
end end
end end
...@@ -157,6 +157,55 @@ RSpec.describe Gitlab::Geo::VerificationState do ...@@ -157,6 +157,55 @@ RSpec.describe Gitlab::Geo::VerificationState do
end end
end end
describe '#track_checksum_attempt!' do
context 'when verification was not yet started' do
it 'starts verification' do
expect do
subject.track_checksum_attempt! do
'a_checksum_value'
end
end.to change { subject.verification_started_at }.from(nil)
end
it 'sets verification_succeeded' do
expect do
subject.track_checksum_attempt! do
'a_checksum_value'
end
end.to change { subject.verification_succeeded? }.from(false).to(true)
end
end
context 'when verification was started' do
it 'does not update verification_started_at' do
subject.verification_started!
expected = subject.verification_started_at
subject.track_checksum_attempt! do
'a_checksum_value'
end
expect(subject.verification_started_at).to be_within(1.second).of(expected)
end
end
it 'yields to the checksum calculation' do
expect do |probe|
subject.track_checksum_attempt!(&probe)
end.to yield_with_no_args
end
context 'when an error occurs while yielding' do
it 'sets verification_failed' do
subject.track_checksum_attempt! do
raise 'an error'
end
expect(subject.reload.verification_failed?).to be_truthy
end
end
end
describe '#verification_succeeded_with_checksum!' do describe '#verification_succeeded_with_checksum!' do
before do before do
subject.verification_started! subject.verification_started!
......
...@@ -22,7 +22,7 @@ RSpec.describe Packages::PackageFile, type: :model do ...@@ -22,7 +22,7 @@ RSpec.describe Packages::PackageFile, type: :model do
context 'new file' do context 'new file' do
it 'calls checksum worker' do it 'calls checksum worker' do
allow(Gitlab::Geo).to receive(:enabled?).and_return(true) stub_primary_node
allow(Geo::VerificationWorker).to receive(:perform_async) allow(Geo::VerificationWorker).to receive(:perform_async)
package_file = create(:conan_package_file, :conan_recipe_file) package_file = create(:conan_package_file, :conan_recipe_file)
......
...@@ -326,30 +326,39 @@ RSpec.shared_examples 'a verifiable replicator' do ...@@ -326,30 +326,39 @@ RSpec.shared_examples 'a verifiable replicator' do
end end
describe '#verify' do describe '#verify' do
context 'on a Geo primary' do it 'wraps the checksum calculation in track_checksum_attempt!' do
tracker = double('tracker', calculate_checksum: 'abc123')
allow(replicator).to receive(:model_record).and_return(tracker)
expect(tracker).to receive(:track_checksum_attempt!).and_yield
replicator.verify
end
end
context 'integration tests' do
before do
model_record.save!
end
context 'on a primary' do
before do before do
stub_primary_node stub_primary_node
end end
context 'when the checksum succeeds' do describe 'background backfill' do
it 'delegates checksum calculation and the state change to model_record' do it 'verifies model records' do
expect(model_record).to receive(:calculate_checksum).and_return('abc123') expect do
expect(model_record).to receive(:verification_succeeded_with_checksum!).with('abc123', kind_of(Time)) Geo::VerificationBatchWorker.new.perform(replicator.replicable_name)
end.to change { model_record.reload.verification_succeeded? }.from(false).to(true)
replicator.verify
end end
end end
context 'when an error is raised during calculate_checksum' do describe 'triggered by events' do
it 'passes the error message' do it 'verifies model records' do
error = StandardError.new('Some exception') expect do
allow(model_record).to receive(:calculate_checksum) do Geo::VerificationWorker.new.perform(replicator.replicable_name, replicator.model_record_id)
raise error end.to change { model_record.reload.verification_succeeded? }.from(false).to(true)
end
expect(model_record).to receive(:verification_failed_with_message!).with('Error calculating the checksum', error)
replicator.verify
end end
end end
end end
......
...@@ -35,7 +35,7 @@ describe('Deploy keys app component', () => { ...@@ -35,7 +35,7 @@ describe('Deploy keys app component', () => {
}); });
const findLoadingIcon = () => wrapper.find('.gl-spinner'); const findLoadingIcon = () => wrapper.find('.gl-spinner');
const findKeyPanels = () => wrapper.findAll('.deploy-keys .nav-links li'); const findKeyPanels = () => wrapper.findAll('.deploy-keys .gl-tabs-nav li');
it('renders loading icon while waiting for request', () => { it('renders loading icon while waiting for request', () => {
mock.onGet(TEST_ENDPOINT).reply(() => new Promise()); mock.onGet(TEST_ENDPOINT).reply(() => new Promise());
...@@ -54,17 +54,14 @@ describe('Deploy keys app component', () => { ...@@ -54,17 +54,14 @@ describe('Deploy keys app component', () => {
}); });
it.each` it.each`
selector | label | count selector
${'.js-deployKeys-tab-enabled_keys'} | ${'Enabled deploy keys'} | ${1} ${'.js-deployKeys-tab-enabled_keys'}
${'.js-deployKeys-tab-available_project_keys'} | ${'Privately accessible deploy keys'} | ${0} ${'.js-deployKeys-tab-available_project_keys'}
${'.js-deployKeys-tab-public_keys'} | ${'Publicly accessible deploy keys'} | ${1} ${'.js-deployKeys-tab-public_keys'}
`('$selector title is $label with keys count equal to $count', ({ selector, label, count }) => { `('$selector title exists', ({ selector }) => {
return mountComponent().then(() => { return mountComponent().then(() => {
const element = wrapper.find(selector); const element = wrapper.find(selector);
expect(element.exists()).toBe(true); expect(element.exists()).toBe(true);
expect(element.text().trim()).toContain(label);
expect(element.find('.badge').text().trim()).toBe(count.toString());
}); });
}); });
......
import Vue from 'vue'; import { mount } from '@vue/test-utils';
import mountComponent from 'helpers/vue_mount_component_helper'; import { GlTab } from '@gitlab/ui';
import navigationTabs from '~/vue_shared/components/navigation_tabs.vue'; import NavigationTabs from '~/vue_shared/components/navigation_tabs.vue';
describe('navigation tabs component', () => { describe('navigation tabs component', () => {
let vm; let wrapper;
let Component;
let data;
beforeEach(() => { const data = [
data = [ {
{ name: 'All',
name: 'All', scope: 'all',
scope: 'all', count: 1,
count: 1, isActive: true,
isActive: true, },
}, {
{ name: 'Pending',
name: 'Pending', scope: 'pending',
scope: 'pending', count: 0,
count: 0, isActive: false,
isActive: false, },
}, {
{ name: 'Running',
name: 'Running', scope: 'running',
scope: 'running', isActive: false,
isActive: false, },
];
const createComponent = () => {
wrapper = mount(NavigationTabs, {
propsData: {
tabs: data,
scope: 'pipelines',
}, },
]; });
};
Component = Vue.extend(navigationTabs); beforeEach(() => {
vm = mountComponent(Component, { tabs: data, scope: 'pipelines' }); createComponent();
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
wrapper = null;
}); });
it('should render tabs', () => { it('should render tabs', () => {
expect(vm.$el.querySelectorAll('li').length).toEqual(data.length); expect(wrapper.findAll(GlTab)).toHaveLength(data.length);
}); });
it('should render active tab', () => { it('should render active tab', () => {
expect(vm.$el.querySelector('.active .js-pipelines-tab-all')).toBeDefined(); expect(wrapper.find('.js-pipelines-tab-all').classes('active')).toBe(true);
}); });
it('should render badge', () => { it('should render badge', () => {
expect(vm.$el.querySelector('.js-pipelines-tab-all .badge').textContent.trim()).toEqual('1'); expect(wrapper.find('.js-pipelines-tab-all').text()).toContain('1');
expect(vm.$el.querySelector('.js-pipelines-tab-pending .badge').textContent.trim()).toEqual( expect(wrapper.find('.js-pipelines-tab-pending').text()).toContain('0');
'0',
);
}); });
it('should not render badge', () => { it('should not render badge', () => {
expect(vm.$el.querySelector('.js-pipelines-tab-running .badge')).toEqual(null); expect(wrapper.find('.js-pipelines-tab-running .badge').exists()).toBe(false);
}); });
it('should trigger onTabClick', () => { it('should trigger onTabClick', async () => {
jest.spyOn(vm, '$emit').mockImplementation(() => {}); await wrapper.find('.js-pipelines-tab-pending').trigger('click');
vm.$el.querySelector('.js-pipelines-tab-pending').click();
expect(vm.$emit).toHaveBeenCalledWith('onChangeTab', 'pending'); expect(wrapper.emitted('onChangeTab')).toEqual([['pending']]);
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment