Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
fix: Failing generator-swiftserver integration tests for SDKGen servi…
Browse files Browse the repository at this point in the history
…ce (#412)
  • Loading branch information
Aaron Liberatore authored and tunniclm committed Jan 10, 2018
1 parent f3b8cdb commit 12269ca
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coverage/
coverage.lcov
.vscode/
*.swp
.DS_Store
26 changes: 7 additions & 19 deletions lib/sdkGenHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ exports.getServerSDKAsync = function (sdkName, generatedID) {
.pipe(unzip.Extract({ path: tempDir }))
.on('close', () => {
debug(`finished server SDK download and unzip for ${sdkName} from ${serverDownloadURL} to ${tempDir}`)

var sdkDir = path.join(tempDir, sdkName)
debug(`reading package dependencies from server SDK ${sdkName} in ${sdkDir}`)
try {
Expand All @@ -158,27 +157,16 @@ function ensureTrailingComma (string) {

function readPackageDependencies (sdkName, sdkDir) {
var originFile = fs.readFileSync(sdkDir + '/Package.swift', 'utf8')
var originMatches = originFile.match(/\.\bPackage\b.*/g)
var parsedDependencies = null
var originMatches = originFile.match(/\.\bpackage\b.*/g)
if (originMatches) {
parsedDependencies = []
// input : .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1, minor: 7)
// output : .package(url: "https://github.com/IBM-Swift/Kitura.git", .upToNextMinor(from : "1.7.0")
originMatches.forEach(function (dependency) {
if (dependency.indexOf('minor') < 0) {
throw Error(chalk.red('SDKGEN Package dependency format is incompatible'))
var re = /\.package\(url:\s"https:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*).git",\s((\.upToNextMajor|\.upToNextMinor)\(from:\s"(-?\d+\.){2}-?\d+"\)|from:\s"(-?\d+\.){2}-?\d+")\),?$/
debug(`found ${originMatches.length} package dependencies in server SDK ${sdkName}`)
return originMatches.map(function (m) {
if (!re.test(m)) {
throw Error(chalk.red('SDKGEN Package dependency format is incompatible with input: ' + m))
}
dependency = dependency.replace('Package', 'package')
var commaSplit = dependency.split(',')
var majorVersion = commaSplit[1].replace(/[^0-9.]/g, '')
var minor = commaSplit[2].replace(/[^0-9.]/g, '')
dependency = commaSplit[0] + ', .upToNextMinor( from:"' + majorVersion + '.' + minor + '.0"))'
parsedDependencies.push(dependency)
return ensureTrailingComma(m.trim())
})
}
if (parsedDependencies) {
debug(`found ${parsedDependencies.length} package dependencies in server SDK ${sdkName}`)
return parsedDependencies.map(m => ensureTrailingComma(m.trim()))
} else {
debug(`found no package dependencies in server SDK ${sdkName}`)
return []
Expand Down
34 changes: 24 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion refresh/templates/common/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let package = Package(
<% }); -%>
]),
<% Object.keys(sdkTargets).forEach(function(target) { -%>
.target(name: "<%- sdkTargets[target] %>", dependencies: ["ObjectMapper","SimpleHttpClient"], path: "Sources/<%- sdkTargets[target] %>" ),
.target(name: "<%- sdkTargets[target] %>", dependencies: ["SimpleHttpClient"], path: "Sources/<%- sdkTargets[target] %>" ),
<% }); -%>
<% }else { _%>
]),
Expand Down
Binary file modified test/resources/dummy_PackageSDK.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion test/unit/refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ describe('Unit tests for swiftserver:refresh', function () {

it(`should throw error`, function () {
assert(error, 'Should throw an error')
assert(error.match(/SDKGEN.*incompatible/), 'Thrown error should be about failing to parse SDK package dependency, it was: ' + error)
assert(error.match(/SDKGEN.*incompatible.*.package\(url: ".*", from: "1\.0"\)/), 'Thrown error should be about failing to parse SDK package dependency, it was: ' + error)
})
})
})
Expand Down

0 comments on commit 12269ca

Please sign in to comment.