Skip to content

Commit

Permalink
regression tests (Azure#31)
Browse files Browse the repository at this point in the history
* add standalone run

* pull in server

* regeneration

* regen

* ci job for diffing

* added specs repo tests

* quirk
  • Loading branch information
olydis authored Nov 9, 2017
1 parent 3125c7c commit 557b34d
Show file tree
Hide file tree
Showing 55 changed files with 221,967 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .gulp/common.iced
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ module.exports =
proc.stdout.on 'data', ondata if ondata
return proc

autorest: (args,done,ignoreexitcode) ->
echo info "Queuing up: AutoRest #{args.join(' ')}"
execute "#{basefolder}/node_modules/.bin/autorest \"--use=#{basefolder}\" #{args.map((a) -> "\"#{a}\"").join(' ')}" , { silent:true, ignoreexitcode: ignoreexitcode || false }, (code,stdout,stderr) ->
return done(code,stdout,stderr)

# build task for global build
module.exports.task 'build', 'builds project', ->
echo "Building project in #{basefolder}"
Expand Down
25 changes: 24 additions & 1 deletion .gulp/gulpfile.iced
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require './common.iced'
# ==============================================================================
# tasks required for this build
Tasks "dotnet" # dotnet functions
Tasks "regeneration"
Tasks "publishing"

# ==============================================================================
Expand All @@ -21,7 +22,29 @@ task 'init', "" ,(done)->

# Run language-specific tests:
# (ie, things that call stuff like 'mvn test', 'npm test', 'tox', 'go run' etc)
task 'test', "more", ["regenerate"], (done) ->
task 'test', "more", [], (done) ->
# insert commands here to do other kinds of testing
# echo "Testing More"
done();

# CI job
task 'testci', "more", [], (done) ->
# install latest AutoRest
await autorest ["--latest"], defer code, stderr, stdout

## TEST SUITE
global.verbose = true
await run "test", defer _

## REGRESSION TEST
global.verbose = false
# regenerate
await run "regenerate", defer _
# diff ('add' first so 'diff' includes untracked files)
await execute "git add -A", defer code, stderr, stdout
await execute "git diff --staged -w", defer code, stderr, stdout
# eval
echo stderr
echo stdout
throw "Potentially unnoticed regression (see diff above)! Run `npm run regenerate`, then review and commit the changes." if stdout.length + stderr.length > 0
done()
113 changes: 113 additions & 0 deletions .gulp/regeneration.iced
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

###############################################
# LEGACY
# Instead: have bunch of configuration files sitting in a well-known spot, discover them, feed them to AutoRest, done.

regenExpected = (opts,done) ->
keys = Object.getOwnPropertyNames(opts.mappings)
instances = keys.length

for kkey in keys
optsMappingsValue = opts.mappings[kkey]
key = kkey.trim();

swaggerFiles = (if optsMappingsValue instanceof Array then optsMappingsValue[0] else optsMappingsValue).split(";")
args = [
"--standalone-modeler",
"--clear-output-folder",
"--output-artifact=code-model-v1.yaml",
"--output-folder=#{opts.outputDir}/#{key}"
]

for swaggerFile in swaggerFiles
args.push("--input-file=#{opts.inputBaseDir}/#{swaggerFile}")

if (opts['override-info.version'])
args.push("--override-info.version=#{opts['override-info.version']}")
if (opts['override-info.title'])
args.push("--override-info.title=#{opts['override-info.title']}")
if (opts['override-info.description'])
args.push("--override-info.description=#{opts['override-info.description']}")

if (argv.args)
for arg in argv.args.split(" ")
args.push(arg);

autorest args,() =>
instances--
return done() if instances is 0

mappingsTestServer = {
'azure-parameter-grouping' : 'azure-parameter-grouping.json',
'azure-report' : 'azure-report.json',
'azure-resource-x' : 'azure-resource-x.json',
'azure-resource' : 'azure-resource.json',
'azure-special-properties' : 'azure-special-properties.json',
'body-array' : 'body-array.json',
'body-boolean' : 'body-boolean.json',
'body-boolean.quirks' : 'body-boolean.quirks.json',
'body-byte' : 'body-byte.json',
'body-complex' : 'body-complex.json',
'body-date' : 'body-date.json',
'body-datetime-rfc1123' : 'body-datetime-rfc1123.json',
'body-datetime' : 'body-datetime.json',
'body-dictionary' : 'body-dictionary.json',
'body-duration' : 'body-duration.json',
'body-file' : 'body-file.json',
'body-formdata-urlencoded' : 'body-formdata-urlencoded.json',
'body-formdata' : 'body-formdata.json',
'body-integer' : 'body-integer.json',
'body-number' : 'body-number.json',
'body-number.quirks' : 'body-number.quirks.json',
'body-string' : 'body-string.json',
'body-string.quirks' : 'body-string.quirks.json',
'complex-model' : 'complex-model.json',
'custom-baseUrl-more-options' : 'custom-baseUrl-more-options.json',
'custom-baseUrl' : 'custom-baseUrl.json',
'extensible-enums-swagger' : 'extensible-enums-swagger.json',
'head-exceptions' : 'head-exceptions.json',
'head' : 'head.json',
'header' : 'header.json',
'httpInfrastructure' : 'httpInfrastructure.json',
'httpInfrastructure.quirks' : 'httpInfrastructure.quirks.json',
'lro' : 'lro.json',
'model-flattening' : 'model-flattening.json',
'paging' : 'paging.json',
'parameter-flattening' : 'parameter-flattening.json',
'report' : 'report.json',
'required-optional' : 'required-optional.json',
'storage' : 'storage.json',
'subscriptionId-apiVersion' : 'subscriptionId-apiVersion.json',
'url-multi-collectionFormat' : 'url-multi-collectionFormat.json',
'url' : 'url.json',
'validation' : 'validation.json'
}

mappingsSpecs = {
'specs-compute' : 'compute/resource-manager/Microsoft.Compute/2017-03-30/compute.json',
'specs-network' : 'network/resource-manager/Microsoft.Network/2017-10-01/network.json',
'specs-web' : 'web/resource-manager/Microsoft.Web/2016-08-01/WebApps.json',
'specs-mobileengagement' : 'mobileengagement/resource-manager/Microsoft.MobileEngagement/2014-12-01/mobile-engagement.json',
'specs-datalake-store' : 'datalake-store/data-plane/Microsoft.DataLakeStore/2016-11-01/filesystem.json',
'specs-search' : 'search/data-plane/Microsoft.Search/2016-09-01/searchindex.json',
'specs-batch' : 'batch/data-plane/Microsoft.Batch/2017-09-01.6.0/BatchService.json'
}

task 'regenerate-testserver', '', (done) ->
regenExpected {
'inputBaseDir': "node_modules/@microsoft.azure/autorest.testserver/swagger",
'mappings': mappingsTestServer,
'outputDir': 'test/Expected'
},done
return null

task 'regenerate-specs', '', (done) ->
regenExpected {
'inputBaseDir': "https://github.com/Azure/azure-rest-api-specs/blob/2df71489cc110ca9d3251bf7a4e685ab6616f379/specification",
'mappings': mappingsSpecs,
'outputDir': 'test/Expected'
},done
return null

task 'regenerate', "regenerate expected code for tests", ['regenerate-testserver', 'regenerate-specs'], (done) ->
done();
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"scripts": {
"start": "dotnet src/bin/netcoreapp2.0/autorest.modeler.dll --server",
"test": "gulp test",
"testci": "gulp test",
"testci": "gulp testci",
"build": "gulp build",
"prepare": "gulp build",
"publish-preview": "gulp publish-preview",
"regenerate": "gulp regenerate",
"clean": "gulp clean",
"nuke": "git clean -xdf"
},
Expand All @@ -28,6 +29,8 @@
},
"homepage": "https://github.com/Azure/autorest.modeler/blob/master/README.md",
"devDependencies": {
"@microsoft.azure/autorest.testserver": "2.3.1",
"autorest": "^2.0.4194",
"coffee-script": "^1.11.1",
"dotnet-sdk-2.0.0": "^1.4.4",
"gulp": "^3.9.1",
Expand All @@ -46,4 +49,4 @@
"dependencies": {
"dotnet-2.0.0": "^1.4.4"
}
}
}
23 changes: 22 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,29 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio

# AutoRest extension configuration

## Run it as a standalone (good for testing)

``` yaml $(standalone-modeler)
pipeline:
standalone/imodeler1:
input: openapi-document/identity
output-artifact: code-model-v1
scope: standalone-modeler
standalone/commonmarker:
input: imodeler1
output-artifact: code-model-v1
standalone/cm/transform:
input: commonmarker
output-artifact: code-model-v1
standalone/cm/emitter:
input: transform
scope: scope-cm/emitter
```
## Run it before generator
``` yaml
# pipeline configuration is part of generators which make use of this extension
# pipeline configuration is part of generators which make use of this extension (modeler must run under generator's scope)

# used by generators:
scope-transform-string:
Expand Down
Loading

0 comments on commit 557b34d

Please sign in to comment.