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 API for creating test result via global data store #103

Merged
merged 8 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
93 changes: 93 additions & 0 deletions apis/datastore.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"openapi": "3.0.0",
"info": {
"description": "A service that orchestrates the Sauce cloud as well as test runner packages.",
"version": "0.1.7",
"title": "Testrunner Data Store Job Orchestrator",
"termsOfService": "https://saucelabs.com/terms-of-service",
"contact": {
"name": "Open Source Program Office at Sauce",
"email": "[email protected]",
"url": "https://saucelabs.com"
}
},
"externalDocs": {
"description": "Sauce Labs Wiki",
"url": "https://wiki.saucelabs.com"
},
"basePath": "/v1/test-results",
"servers": [
{
"url": "https://api.{region}.saucelabs.{tld}",
"variables": {
"region": {
"default": "us-west-1",
"description": "region of datacenter",
"enum": [
"us-west-1",
"eu-central-1",
"staging"
]
},
"tld": {
"default": "com",
"description": "internal or external API",
"enum": [
"net",
"com"
]
}
}
}
],
"components": {
"securitySchemes": {
"bearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
},
"basicAuth": {
"type": "http",
"scheme": "basic"
}
}
},
"paths": {
"/": {
"post": {
"description": "create test result job via data store",
"operationId": "createTestResult",
"parameters": [
{
"name": "parameters",
"required": true,
"description": "create test result job request body",
"schema": {
"type": "string"
}
}
],
"externalDocs": {
"description": "TBD",
"url": "https://wiki.saucelabs.com"
},
"tags": [
"Job"
],
"responses": {
"200": {
"description": "create test result job",
"content": {
"application/json": {
"schema": {
"type": "json"
}
}
}
}
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const run = () => {
yargs.positional(param.name, paramDescription)
}
}, async (argv) => {
const { user, key, headless, region, proxy } = Object.assign({}, DEFAULT_OPTIONS, argv)
const api = new SauceLabs({ user, key, headless, region, proxy })
const { user, key, headless, region, proxy, tld } = Object.assign({}, DEFAULT_OPTIONS, argv)
const api = new SauceLabs({ user, key, headless, region, proxy, tld })
const requiredParams = params.filter((p) => p.required).map((p) => argv[p.name])

try {
Expand Down
4 changes: 2 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const protocols = [
require('../apis/sauce.json'),
require('../apis/rdc.json'),
require('../apis/performance.json'),
require('../apis/testrunner.json')
require('../apis/testrunner.json'),
require('../apis/datastore.json')
]

const protocolFlattened = new Map()
Expand All @@ -31,7 +32,6 @@ for (const { paths, parameters, basePath, servers } of protocols) {
for (const [endpoint, methods] of Object.entries(paths)) {
for (const [method, description] of Object.entries(methods)) {
let commandName = camelCase(description.operationId)

/**
* mark commands as depcrecated in the command names
*/
Expand Down
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export default class SauceLabs {
return ::this._uploadJobAssets
}

if (propName === 'createTestResult') {
return ::this._createTestResult
}
tianfeng92 marked this conversation as resolved.
Show resolved Hide resolved

/**
* allow to return publicly registered class properties
*/
Expand Down Expand Up @@ -381,4 +385,25 @@ export default class SauceLabs {
throw new Error(`There was an error uploading assets: ${err.message}`)
}
}

async _createTestResult(parameters) {
const { servers, basePath, method, endpoint } = PROTOCOL_MAP.get('createTestResult')
const uri = getAPIHost(servers, basePath, this._options) + endpoint

try {
const res = await this._api(uri, {
method,
hooks: {
beforeRequest: [
options => {
options.body = parameters;
}
]
}
})
return res.body;
} catch (err) {
throw new Error(`There was an error create test results: ${err.message}`)
}
}
}