Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for object replacement in suspended buckets #5713

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ env:
# https://github.com/git-lfs/git-lfs/issues/5749
GIT_CLONE_PROTECTION_ACTIVE: 'false'
jobs:
linting-coverage:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -87,10 +87,7 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip
cache: pip
- name: Install python deps
run: pip install flake8
- name: Lint Javascript
Expand All @@ -101,19 +98,41 @@ jobs:
run: flake8 $(git ls-files "*.py")
- name: Lint Yaml
run: yamllint -c yamllint.yml $(git ls-files "*.yml")

unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '16'
cache: yarn
- name: install typescript
shell: bash
run: yarn global add [email protected]
- name: install dependencies
run: yarn install --frozen-lockfile --network-concurrency 1
- name: Unit Coverage
run: |
set -ex
mkdir -p $CIRCLE_TEST_REPORTS/unit
yarn test
yarn run test_legacy_location
yarn run cover test
yarn run cover test_legacy_location
env:
S3_LOCATION_FILE: tests/locationConfig/locationConfigTests.json
CIRCLE_TEST_REPORTS: /tmp
CIRCLE_ARTIFACTS: /tmp
CI_REPORTS: /tmp
- name: Unit Coverage logs
run: find /tmp/unit -exec cat {} \;
- name: Upload test results to Codecov
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: '**/junit/*junit*.xml'
flags: unit
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage/test
flags: unit
if: ${{ !cancelled() }}
- name: preparing junit files for upload
run: |
mkdir -p artifacts/junit
Expand Down
10 changes: 10 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"all": true,
"include": [
"bin/**/*.js",
"lib/**/*.js"
],
"exclude": [
"tests/**/*.js"
]
}
39 changes: 39 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
parsers:
javascript:
enable_partials: yes

comment:
layout: newheader, reach, files, components, diff, flags # show component info in the PR comment
hide_comment_details: true # hide the comment details (e.g. coverage targets) in the PR comment

# Setting coverage targets
coverage:
status:
project:
default:
target: auto
threshold: 1%
removed_code_behavior: adjust_base
paths:
- bin
- lib
patch:
default:
target: 80%

component_management:
default_rules: # default rules that will be inherited by all components
statuses: []

flag_management:
default_rules: # the rules that will be followed for any flag added, generally
carryforward: true
statuses: []

# Do not consider zenko integration builds in coverage comparisons
flags:
zenko-end2end-sharded:
joined: false
zenko-ctst-end2end-sharded:
joined: false
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@
"eslint-plugin-mocha": "^10.1.0",
"express": "^4.17.1",
"ioredis": "4.9.5",
"istanbul": "1.0.0-alpha.2",
"istanbul-api": "1.0.0-alpha.13",
"lolex": "^1.4.0",
"mocha": "^2.3.4",
"mocha-junit-reporter": "^1.23.1",
"mocha-multi-reporters": "^1.1.7",
"node-mocks-http": "1.5.2",
"nyc": "^15.1.0",
"sinon": "^13.0.1",
"tv4": "^1.2.7"
},
Expand Down Expand Up @@ -116,7 +115,7 @@
"test_utapi_v2": "mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json --recursive tests/utapi",
"test_quota": "mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json --recursive tests/quota",
"multiple_backend_test": "CI=true S3BACKEND=mem S3DATA=multiple mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json -t 20000 --recursive tests/multipleBackend",
"unit_coverage": "CI=true mkdir -p coverage/unit/ && S3BACKEND=mem istanbul cover --dir coverage/unit _mocha -- --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json --recursive tests/unit",
"unit_coverage_legacy_location": "CI=true mkdir -p coverage/unitlegacylocation/ && S3_LOCATION_FILE=tests/locationConfig/locationConfigLegacy.json S3BACKEND=mem istanbul cover --dir coverage/unitlegacylocation _mocha -- --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json --reporter mocha-junit-reporter --recursive tests/unit"
"cover": "nyc --clean --silent yarn run",
"postcover": "nyc report --report-dir ./coverage/test --reporter=lcov"
}
}
56 changes: 36 additions & 20 deletions tests/unit/api/apiUtils/quotas/quotaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
isMetricStale,
} = require('../../../../../lib/api/apiUtils/quotas/quotaUtils');
const QuotaService = require('../../../../../lib/quotas/quotas');
const BucketInfo = require('arsenal').models.BucketInfo;

const mockLog = {
warn: sinon.stub(),
Expand Down Expand Up @@ -637,28 +638,43 @@ describe('processBytesToWrite', () => {

[
// non versionned case
['the content-length when deleting hot object', hotObject, false, undefined, -100],
['0 when deleting cold object', coldObject, false, undefined, 0],
['the content-length when deleting restoring object', restoringObject, false, undefined, -100],
['the content-length when deleting restored object', restoredObject, false, undefined, -100],
['the content-length when deleting expired object', expiredObject, false, undefined, -100],
['the length when deleting hot object', hotObject, 'disabled', undefined, -100],
['0 when deleting cold object', coldObject, 'disabled', undefined, 0],
['the length when deleting restoring object', restoringObject, 'disabled', undefined, -100],
['the length when deleting restored object', restoredObject, 'disabled', undefined, -100],
['the length when deleting expired object', expiredObject, 'disabled', undefined, -100],

// versionned case
['the content-length when deleting hot object version', hotObject, true, 'versionId', -100],
['0 when deleting cold versioned object version', coldObject, true, 'versionId', 0],
['the content-length when deleting restoring object version', restoringObject, true, 'versionId', -100],
['the content-length when deleting restored object version', restoredObject, true, 'versionId', -100],
['the content-length when deleting expired object version', expiredObject, true, 'versionId', -100],

// delete marker case
['0 when adding delete marker over hot object', hotObject, true, undefined, 0],
['0 when adding delete marker over cold object', coldObject, true, undefined, 0],
['0 when adding delete marker over restoring object', restoringObject, true, undefined, 0],
['0 when adding delete marker over restored object', restoredObject, true, undefined, 0],
['0 when adding delete marker over expired object', expiredObject, true, undefined, 0],
].forEach(([scenario, object, versionned, reqVersionId, expected]) => {
it(`should return ${scenario}`, () => {
bucket.isVersioningEnabled.returns(versionned);
['the length when deleting hot object version', hotObject, 'Enabled', 'versionId', -100],
['0 when deleting cold versioned object version', coldObject, 'Enabled', 'versionId', 0],
['the length when deleting restoring object version', restoringObject, 'Enabled', 'versionId', -100],
['the length when deleting restored object version', restoredObject, 'Enabled', 'versionId', -100],
['the length when deleting expired object version', expiredObject, 'Enabled', 'versionId', -100],

// delete marker in versionned case
['0 when adding delete marker over hot object', hotObject, 'Enabled', undefined, 0],
['0 when adding delete marker over cold object', coldObject, 'Enabled', undefined, 0],
['0 when adding delete marker over restoring object', restoringObject, 'Enabled', undefined, 0],
['0 when adding delete marker over restored object', restoredObject, 'Enabled', undefined, 0],
['0 when adding delete marker over expired object', expiredObject, 'Enabled', undefined, 0],

// version-suspended case
['the length when deleting hot object version', hotObject, 'Suspended', 'versionId', -100],
['0 when deleting cold versioned object version', coldObject, 'Suspended', 'versionId', 0],
['the length when deleting restoring object version', restoringObject, 'Suspended', 'versionId', -100],
['the length when deleting restored object version', restoredObject, 'Suspended', 'versionId', -100],
['the length when deleting expired object version', expiredObject, 'Suspended', 'versionId', -100],

// delete marker in version-suspended case
['the length when adding delete marker over hot object', hotObject, 'Suspended', undefined, -100],
['0 when adding delete marker over cold object', coldObject, 'Suspended', undefined, 0],
['the length when adding delete marker over restoring object', restoringObject, 'Suspended', undefined, -100],
['the length when adding delete marker over restored object', restoredObject, 'Suspended', undefined, -100],
['the length when adding delete marker over expired object', expiredObject, 'Suspended', undefined, -100],
].forEach(([scenario, object, versioningStatus, reqVersionId, expected]) => {
it(`should return ${scenario} and versioning is ${versioningStatus}`, () => {
const bucket = new BucketInfo('bucketName', 'ownerId', 'ownerName', new Date().toISOString());
bucket.setVersioningConfiguration({ Status: versioningStatus });
objMD = object;

const bytes = processBytesToWrite('objectDelete', bucket, reqVersionId, 0, objMD);
Expand Down
Loading
Loading