-
Notifications
You must be signed in to change notification settings - Fork 301
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
Artifact creation and validation #2540
Merged
mickeyryan42
merged 37 commits into
release
from
campfire/NR-268461-build-validate-artifact
Sep 9, 2024
+608
−392
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
0311ab2
WIP: Creating and validating artifact
68085ff
WIP: Cleanup
d1a7f25
feat: Update schema validation
bcc7ab4
fix: Properly get all datasource definitions
1e6e183
feat: First pass at error output
1de35c9
feat: Add community dataSourceIds
0cabd35
refactor: Rename datasource to dataSource
0b0ad40
feat: Additional error output formatting
1be1bd8
WIP: Creating and validating artifact
c5107b6
WIP: Cleanup
556b9cd
fix: Properly get all datasource definitions
76d9594
feat: First pass at error output
e9ef407
feat: Add community dataSourceIds
b1c5eb6
refactor: Rename datasource to dataSource
3a4ddf7
feat: Additional error output formatting
82ccc25
chore: Resolving merge conflicts
zstix 5343088
refactor: Broke up large script to smaller, composable, functions
zstix 5338b6b
feat: Fix configs for validation
mickeyryan42 ec3ceb6
feat: Fix config issues for validation
mickeyryan42 3e48902
feat: Remove extra filter
0ee8e1f
refactor: Minor cleanup with error parsing
0c3e0e6
fix: Correctly fetch all alerts
84cfe43
chore: Move comment to the right place
9fbe659
fix: Correct mongo operator
a54677a
feat: Update alerts schema
912a627
chore: Remove debug log
162893d
Merge branch 'campfire/NR-268461-config-fixes' of https://github.com/…
mickeyryan42 6c44419
refactor: Add a type guard function to remove the need for `as`
zstix 8bb1b46
chore: Reverted flexibility with install directives
zstix ebb74da
chore: Show a success message when script encounters no errors
zstix 533e844
refactor: Pull in lodash/get to make access to nested object easier
zstix 9c39df9
chore: Remove unecessary whitespace
zstix 2669874
chore: Slightly less permissive types
zstix ba9fc77
refactor: Separated error formatting from printing
zstix c10fc26
test: Ensure logic is correct for building and validating artifact
zstix 1823bef
Merge branch 'campfire/NR-268461-build-validate-artifact' of https://…
mickeyryan42 a8d98bf
test: Add alert and dashboard to tests
mickeyryan42 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
Loading status checks…
test: Ensure logic is correct for building and validating artifact
- v0.126.0-pre.594433b55
- v0.126.0-pre.60e32910a
- v0.126.0-pre.7caabaabc
- v0.126.0-pre.5c70086b0
- v0.126.0-pre.4cbbd1df3
- v0.126.0-pre.f4ddc09a7
- v0.126.0-pre.e1b2c2331
- v0.126.0-pre.c14311df6
- v0.126.0-pre.bde0e2801
- v0.126.0-pre.ba43bfa38
- v0.126.0-pre.b91577f77
- v0.126.0-pre.b4330b1e5
- v0.126.0-pre.a86f0213e
- v0.126.0-pre.a28ed3955
- v0.125.1
- v0.125.0
- v0.124.3
- v0.124.2
- v0.124.1
- v0.124.0
- v0.123.0
- v0.122.0
- v0.0.1
commit c10fc26b834082d2b44739b647b37edc6a49b14a
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
utils/__tests__/build-validate-quickstart-artifact.test.js
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,163 @@ | ||
import * as fs from 'fs'; | ||
import Quickstart from '../lib/Quickstart'; | ||
import DataSource from '../lib/DataSource'; | ||
import Alert from '../lib/Alert'; | ||
import Dashboard from '../lib/Dashboard'; | ||
|
||
import { | ||
getArtifactComponents, | ||
getDataSourceIds, | ||
validateArtifact, | ||
} from '../build-validate-quickstart-artifact'; | ||
|
||
jest.mock('../lib/Quickstart'); | ||
jest.mock('../lib/DataSource'); | ||
jest.mock('../lib/Alert'); | ||
jest.mock('../lib/Dashboard'); | ||
jest.mock('fs'); | ||
|
||
describe('built-validate-quickstart-artifact', () => { | ||
beforeEach(() => { | ||
// disable normal logging used as feedback while script runs | ||
jest.spyOn(console, 'log').mockImplementation(() => {}); | ||
}); | ||
|
||
describe('build', () => { | ||
it('should find all of the components', () => { | ||
Quickstart.getAll = jest | ||
.fn() | ||
.mockReturnValueOnce([ | ||
{ config: 'test-quickstart-1' }, | ||
{ config: 'test-quickstart-2' }, | ||
]); | ||
|
||
DataSource.getAll = jest | ||
.fn() | ||
.mockReturnValueOnce([{ config: 'test-dataSource-1' }]); | ||
|
||
Alert.getAll = jest.fn().mockReturnValueOnce([]); | ||
Dashboard.getAll = jest.fn().mockReturnValueOnce([]); | ||
|
||
const actual = getArtifactComponents(); | ||
|
||
expect(actual.quickstarts).toHaveLength(2); | ||
expect(actual.quickstarts[0]).toEqual('test-quickstart-1'); | ||
expect(actual.quickstarts[1]).toEqual('test-quickstart-2'); | ||
expect(actual.dataSources).toHaveLength(1); | ||
expect(actual.dataSources[0]).toEqual('test-dataSource-1'); | ||
expect(actual.alerts).toHaveLength(0); | ||
expect(actual.dashboards).toHaveLength(0); | ||
}); | ||
|
||
it('should produce a complete list of dataSource IDs', () => { | ||
Quickstart.getAll = jest.fn().mockReturnValueOnce([]); | ||
Alert.getAll = jest.fn().mockReturnValueOnce([]); | ||
Dashboard.getAll = jest.fn().mockReturnValueOnce([]); | ||
DataSource.getAll = jest | ||
.fn() | ||
.mockReturnValueOnce([ | ||
{ config: { id: 'community-1' } }, | ||
{ config: { id: 'community-2' } }, | ||
{ config: { id: 'community-3' } }, | ||
]); | ||
|
||
const { dataSources } = getArtifactComponents(); | ||
fs.readFileSync.mockReturnValueOnce(JSON.stringify(['core-1', 'core-2'])); | ||
|
||
const actual = getDataSourceIds('dummy-file.json', dataSources); | ||
|
||
expect(actual).toHaveLength(5); | ||
expect(actual).toContain('community-1'); | ||
expect(actual).toContain('community-2'); | ||
expect(actual).toContain('community-3'); | ||
expect(actual).toContain('core-1'); | ||
expect(actual).toContain('core-2'); | ||
}); | ||
}); | ||
|
||
describe('validate', () => { | ||
const TEST_SCHEMA = { | ||
type: 'object', | ||
properties: { | ||
quickstarts: { type: 'array' }, | ||
alerts: { type: 'array' }, | ||
dashboards: { type: 'array' }, | ||
dataSources: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
id: { type: 'string' }, | ||
title: { type: 'string' }, | ||
}, | ||
}, | ||
}, | ||
getDataSourceIds: { type: 'array', items: { type: 'string' } }, | ||
}, | ||
}; | ||
|
||
it('should correctly build and validate valid artifacts with no errors', () => { | ||
Quickstart.getAll = jest.fn().mockReturnValueOnce([]); | ||
Alert.getAll = jest.fn().mockReturnValueOnce([]); | ||
Dashboard.getAll = jest.fn().mockReturnValueOnce([]); | ||
DataSource.getAll = jest | ||
.fn() | ||
.mockReturnValueOnce([ | ||
{ config: { id: 'community-1', title: 'DataSource 1' } }, | ||
{ config: { id: 'community-2', title: 'DataSource 2' } }, | ||
{ config: { id: 'community-3', title: 'DataSource 3' } }, | ||
]); | ||
|
||
const components = getArtifactComponents(); | ||
|
||
fs.readFileSync.mockReturnValueOnce(JSON.stringify(['core-1', 'core-2'])); | ||
const dataSourceIds = getDataSourceIds( | ||
'dummy-file.json', | ||
components.dataSources | ||
); | ||
|
||
const artifact = { ...components, dataSourceIds }; | ||
|
||
const actual = validateArtifact(TEST_SCHEMA, artifact); | ||
|
||
expect(actual).toHaveLength(0); | ||
}); | ||
|
||
it('should correctly return errors for an invalid artifact', () => { | ||
Quickstart.getAll = jest.fn().mockReturnValueOnce([]); | ||
Alert.getAll = jest.fn().mockReturnValueOnce([]); | ||
Dashboard.getAll = jest.fn().mockReturnValueOnce([]); | ||
DataSource.getAll = jest | ||
.fn() | ||
.mockReturnValueOnce([ | ||
{ config: { id: 'community-1', title: 'DataSource 1' } }, | ||
{ config: { id: false, title: 'DataSource 2' } }, | ||
{ config: { id: 'community-3', title: 3 } }, | ||
]); | ||
|
||
const components = getArtifactComponents(); | ||
|
||
fs.readFileSync.mockReturnValueOnce(JSON.stringify(['core-1', 'core-2'])); | ||
const dataSourceIds = getDataSourceIds( | ||
'dummy-file.json', | ||
components.dataSources | ||
); | ||
|
||
const artifact = { ...components, dataSourceIds }; | ||
|
||
const actual = validateArtifact(TEST_SCHEMA, artifact); | ||
|
||
expect(actual).toHaveLength(2); | ||
expect(actual).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
instancePath: '/dataSources/1/id', | ||
}), | ||
expect.objectContaining({ | ||
instancePath: '/dataSources/2/title', | ||
}), | ||
]) | ||
); | ||
}); | ||
}); | ||
}); |
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.
we might want to test each of these with non-empty values here since we had problems with the getAll returning nothing before!