-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Fleet] Add fetch package unit tests #134768
Merged
hop-dev
merged 6 commits into
elastic:main
from
hop-dev:127167-registry-fetch-unit-tests
Jun 20, 2022
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee6a4c9
move getPathParts tests into describe block
hop-dev 5b0452a
move archive tests to archive folder
hop-dev e6e6761
fetchFindLatestPackageOrUndefined tests
hop-dev 566683f
fetchFindLatestPackageOrThrow test
hop-dev b97ff50
move generic tests to util fn
hop-dev 97c0820
fix spelling
hop-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
x-pack/plugins/fleet/server/services/epm/archive/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { AssetParts } from '../../../types'; | ||
|
||
import { getBufferExtractor, getPathParts, untarBuffer, unzipBuffer } from '.'; | ||
|
||
describe('getPathParts', () => { | ||
const testPaths = [ | ||
{ | ||
path: 'foo-1.1.0/service/type/file.yml', | ||
assetParts: { | ||
dataset: undefined, | ||
file: 'file.yml', | ||
path: 'foo-1.1.0/service/type/file.yml', | ||
pkgkey: 'foo-1.1.0', | ||
service: 'service', | ||
type: 'type', | ||
}, | ||
}, | ||
{ | ||
path: 'iptables-1.0.4/kibana/visualization/683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', | ||
assetParts: { | ||
dataset: undefined, | ||
file: '683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', | ||
path: 'iptables-1.0.4/kibana/visualization/683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', | ||
pkgkey: 'iptables-1.0.4', | ||
service: 'kibana', | ||
type: 'visualization', | ||
}, | ||
}, | ||
{ | ||
path: 'coredns-1.0.1/data_stream/stats/fields/coredns.stats.yml', | ||
assetParts: { | ||
dataset: 'stats', | ||
file: 'coredns.stats.yml', | ||
path: 'coredns-1.0.1/data_stream/stats/fields/coredns.stats.yml', | ||
pkgkey: 'coredns-1.0.1', | ||
service: '', | ||
type: 'fields', | ||
}, | ||
}, | ||
]; | ||
test('testPathParts', () => { | ||
for (const value of testPaths) { | ||
expect(getPathParts(value.path)).toStrictEqual(value.assetParts as AssetParts); | ||
} | ||
}); | ||
}); | ||
|
||
describe('getBufferExtractor called with { archivePath }', () => { | ||
it('returns unzipBuffer if `archivePath` ends in .zip', () => { | ||
const extractor = getBufferExtractor({ archivePath: '.zip' }); | ||
expect(extractor).toBe(unzipBuffer); | ||
}); | ||
|
||
it('returns untarBuffer if `archivePath` ends in .gz', () => { | ||
const extractor = getBufferExtractor({ archivePath: '.gz' }); | ||
expect(extractor).toBe(untarBuffer); | ||
const extractor2 = getBufferExtractor({ archivePath: '.tar.gz' }); | ||
expect(extractor2).toBe(untarBuffer); | ||
}); | ||
|
||
it('returns `undefined` if `archivePath` ends in anything else', () => { | ||
const extractor = getBufferExtractor({ archivePath: '.xyz' }); | ||
expect(extractor).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('getBufferExtractor called with { contentType }', () => { | ||
it('returns unzipBuffer if `contentType` is `application/zip`', () => { | ||
const extractor = getBufferExtractor({ contentType: 'application/zip' }); | ||
expect(extractor).toBe(unzipBuffer); | ||
}); | ||
|
||
it('returns untarBuffer if `contentType` is `application/gzip`', () => { | ||
const extractor = getBufferExtractor({ contentType: 'application/gzip' }); | ||
expect(extractor).toBe(untarBuffer); | ||
}); | ||
|
||
it('returns `undefined` if `contentType` ends in anything else', () => { | ||
const extractor = getBufferExtractor({ contentType: '.xyz' }); | ||
expect(extractor).toEqual(undefined); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these tests haven't been changed, only moved to be next to the code they test