Skip to content

Commit

Permalink
Primary fields are in the mapping now
Browse files Browse the repository at this point in the history
- Got the fields in
- Got the tests working
- Time to add convenience fields
  • Loading branch information
manchicken committed Jun 21, 2023
1 parent 77781c1 commit 650ff3b
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 10 deletions.
107 changes: 107 additions & 0 deletions __tests__/lib/fieldMappings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,113 @@ opsgenie:
input: 'app-name',
value: { application: 'app-name' },
},
{
version: 'v2',
field: 'description',
input: 'some description',
value: {
error:
'Sorry, but the «description» field is not avaiable in version v2 of the Datadog Service Catalog schema; this field is only available in version(s): v2.1',
},
},
{
version: 'v2.1',
field: 'description',
input: 'some description',
value: { description: 'some description' },
},
{
version: 'v2',
field: 'tier',
input: 'high',
value: {
error:
'Sorry, but the «tier» field is not avaiable in version v2 of the Datadog Service Catalog schema; this field is only available in version(s): v2.1',
},
},
{
version: 'v2.1',
field: 'tier',
input: 'high',
value: { tier: 'high' },
},
{
version: 'v2',
field: 'lifecycle',
input: 'production',
value: {
error:
'Sorry, but the «lifecycle» field is not avaiable in version v2 of the Datadog Service Catalog schema; this field is only available in version(s): v2.1',
},
},
{
version: 'v2.1',
field: 'lifecycle',
input: 'production',
value: { lifecycle: 'production' },
},
{
version: 'v2',
field: 'docs',
input: `
- name: 'first-doc'
provider: jira
url: https://my-org.atlassian.net/wiki/spaces/PROJ/pages/1234567890
`,
value: {
docs: [
{
name: 'first-doc',
provider: 'jira',
url: 'https://my-org.atlassian.net/wiki/spaces/PROJ/pages/1234567890',
},
],
},
},
{
version: 'v2.1',
field: 'docs',
input: `
- name: 'first-doc'
provider: jira
url: https://my-org.atlassian.net/wiki/spaces/PROJ/pages/1234567890
`,
value: {
error:
'Sorry, but the «docs» field is not avaiable in version v2.1 of the Datadog Service Catalog schema; this field is only available in version(s): v2',
},
},
{
version: 'v2',
field: 'repos',
input: `
- name: 'first-repo'
provider: github
url: https://github.com/arcxp/datadog-service-catalog-metadata-provider
`,
value: {
repos: [
{
name: 'first-repo',
provider: 'github',
url: 'https://github.com/arcxp/datadog-service-catalog-metadata-provider',
},
],
},
},
{
version: 'v2.1',
field: 'repos',
input: `
- name: 'first-repo'
provider: github
url: https://github.com/arcxp/datadog-service-catalog-metadata-provider
`,
value: {
error:
'Sorry, but the «repos» field is not avaiable in version v2.1 of the Datadog Service Catalog schema; this field is only available in version(s): v2',
},
},
])('$field:$version', ({ version, field, input, value }) => {
beforeEach(() => {
core.setFailed.mockClear()
Expand Down
38 changes: 28 additions & 10 deletions lib/fieldMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const mapToUsing = (input, func) => (value) => func(input, value)
const passThru = (input, value) => ({ [input]: value })
const skipField = (_input, _value) => ({})
const simpleYamlParse = (input, str) => ({ [input]: expandObjectInputs(str) })
const arrayYamlParse = (input, str) => ({
[input]: forceArray(expandObjectInputs(str)),
})
const objectYamlParse = (input, str) => ({
[input]: forceObject(expandObjectInputs(str)),
})

const versionCompatibilityError =
(field, chosenVersion, validVersions) => (_input) =>
Expand Down Expand Up @@ -45,7 +51,7 @@ const mappings = {

contacts: useSharedMappings(
['v2', 'v2.1'],
mapToUsing('contacts', simpleYamlParse),
mapToUsing('contacts', arrayYamlParse),
),

// This tags setup is a little hairy, but the biggest thing
Expand Down Expand Up @@ -77,26 +83,38 @@ const mappings = {

integrations: useSharedMappings(
['v2', 'v2.1'],
mapToUsing('integrations', simpleYamlParse),
mapToUsing('integrations', objectYamlParse),
),
// ({
// integrations: forceObject(expandObjectInputs(input)),
// })),

docs: {},
docs: {
v2: mapToUsing('docs', arrayYamlParse),
'v2.1': versionCompatibilityError('docs', 'v2.1', ['v2']),
},

repos: {},
repos: {
v2: mapToUsing('repos', arrayYamlParse),
'v2.1': versionCompatibilityError('repos', 'v2.1', ['v2']),
},

application: {
v2: versionCompatibilityError('application', 'v2', ['v2.1']),
'v2.1': mapToUsing('application', passThru),
},

description: {},
description: {
v2: versionCompatibilityError('description', 'v2', ['v2.1']),
'v2.1': mapToUsing('description', passThru),
},

tier: {},
tier: {
v2: versionCompatibilityError('tier', 'v2', ['v2.1']),
'v2.1': mapToUsing('tier', passThru),
},

lifecycle: {},
lifecycle: {
v2: versionCompatibilityError('lifecycle', 'v2', ['v2.1']),
'v2.1': mapToUsing('lifecycle', passThru),
},

email: {},

Expand Down

0 comments on commit 650ff3b

Please sign in to comment.