-
Notifications
You must be signed in to change notification settings - Fork 89
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 support for openmetrics 0.0.1 besides 1.0.0 #1640
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a31bbf1
added support for older openmetrics versions
rg2011 66882b3
fix openmetrics version
rg2011 2e7c625
imporve accept header
rg2011 0927149
fixed undefined var
rg2011 f9ebf3b
fix typo
rg2011 6ddfd9a
fix doc
rg2011 373c87f
fixed lint issue
rg2011 d45a4e2
test accept headers
rg2011 bc6caf8
remove wrong comment
rg2011 679813e
fix literals
rg2011 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
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
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
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,167 @@ | ||
/* | ||
* Copyright 2024 Telefonica Investigación y Desarrollo, S.A.U | ||
* | ||
* This file is part of fiware-iotagent-lib | ||
* | ||
* fiware-iotagent-lib is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the License, | ||
* or (at your option) any later version. | ||
* | ||
* fiware-iotagent-lib is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with fiware-iotagent-lib. | ||
* If not, see http://www.gnu.org/licenses/. | ||
* | ||
* For those usages not covered by the GNU Affero General Public License | ||
* please contact with::daniel.moranjimenez@telefonica.com | ||
*/ | ||
|
||
/* eslint-disable no-unused-vars */ | ||
|
||
const statsRegistry = require('../../../lib/services/stats/statsRegistry'); | ||
const should = require('should'); | ||
|
||
describe('statsRegistry - openmetrics endpoint', function () { | ||
|
||
const testCases = [ | ||
{ | ||
description: 'Should accept standard openmetrics 0.0.1 header', | ||
accept: 'application/openmetrics-text; version=0.0.1; charset=utf-8', | ||
contentType: { | ||
mediaType: 'application/openmetrics-text', | ||
version: '0.0.1', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should accept standard openmetrics 1.0.0 header', | ||
accept: 'application/openmetrics-text; version=1.0.0; charset=utf-8', | ||
contentType: { | ||
mediaType: 'application/openmetrics-text', | ||
version: '1.0.0', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should accept openmetrics with no version', | ||
accept: 'application/openmetrics-text', | ||
contentType: { | ||
mediaType: 'application/openmetrics-text', | ||
version: '1.0.0', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should accept text/plain header with version', | ||
accept: 'text/plain; version=0.0.4', | ||
contentType: { | ||
mediaType: 'text/plain', | ||
version: '0.0.4', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should accept wildcard header', | ||
accept: '*/*', | ||
contentType: { | ||
mediaType: 'text/plain', | ||
version: '0.0.4', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should accept both openmetrics and text/plain, prefer openmetrics', | ||
accept: 'application/openmetrics-text; version=0.0.1; charset=utf-8,text/plain;version=0.0.4', | ||
contentType: { | ||
mediaType: 'application/openmetrics-text', | ||
version: '0.0.1', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should accept both text/plain and openmetrics, prefer openmetrics', | ||
accept: 'text/plain,application/openmetrics-text; version=0.0.1; charset=utf-8', | ||
contentType: { | ||
mediaType: 'application/openmetrics-text', | ||
version: '0.0.1', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should accept both openmetrics and text/plain, prefer text if preference set', | ||
accept: 'application/openmetrics-text; version=0.0.1; charset=utf-8;q=0.5,text/plain;q=0.7', | ||
contentType: { | ||
mediaType: 'text/plain', | ||
version: '0.0.4', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should match version to content-type', | ||
accept: 'application/openmetrics-text; version=0.0.1; charset=utf-8, text/plain;version=1.0.0', | ||
contentType: { | ||
mediaType: 'application/openmetrics-text', | ||
version: '0.0.1', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should set default q to 1.0', | ||
accept: 'application/openmetrics-text; version=0.0.1; q=0.5,text/plain;version=0.0.4', | ||
contentType: { | ||
mediaType: 'text/plain', | ||
version: '0.0.4', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should accept mixture of content-types and q', | ||
accept: 'application/openmetrics-text; version=0.0.1,text/plain;version=0.0.4;q=0.5,*/*;q=0.1', | ||
contentType: { | ||
mediaType: 'application/openmetrics-text', | ||
version: '0.0.1', | ||
charset: 'utf-8' | ||
} | ||
}, | ||
{ | ||
description: 'Should reject Invalid charset', | ||
accept: '*/*; charset=utf-16', | ||
contentType: null | ||
}, | ||
{ | ||
description: 'Should reject Invalid openmetrics version', | ||
accept: 'application/openmetrics-text; version=0.0.5', | ||
contentType: null | ||
}, | ||
{ | ||
description: 'Should reject Invalid text/plain', | ||
accept: 'text/plain; version=0.0.2', | ||
contentType: null | ||
} | ||
] | ||
|
||
for (const testCase of testCases) { | ||
describe(testCase.description, function () { | ||
const result = statsRegistry.matchContentType(testCase.accept); | ||
if (testCase.contentType) { | ||
it('should match', function (done) { | ||
should.exist(result); | ||
result.mediaType.should.equal(testCase.contentType.mediaType); | ||
result.version.should.equal(testCase.contentType.version); | ||
result.charset.should.equal(testCase.contentType.charset); | ||
done(); | ||
}); | ||
} else { | ||
it('should not match', function (done) { | ||
should.not.exist(result); | ||
done(); | ||
}); | ||
} | ||
}); | ||
} | ||
}); |
Oops, something went wrong.
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.
In order to avoid magic numbers maybe it's better this way:
(Code not actually tested, it may not run, but you get the idea :)
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.
fix in 679813e