Skip to content

Commit

Permalink
feat: enable publishing of verification results
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Jun 4, 2020
1 parent 626cbc6 commit fcbdb3e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 9 deletions.
66 changes: 60 additions & 6 deletions native/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ pub fn verify_provider(mut cx: FunctionContext) -> JsResult<JsUndefined> {
// consumerVersionTag?: string | string[]
// providerVersionTag?: string | string[]
// customProviderHeaders?: string[]
// publishVerificationResult?: boolean
// providerVersion?: string
// tags?: string[]

let mut provider_info = ProviderInfo {
name: provider.clone(),
Expand Down Expand Up @@ -358,14 +355,71 @@ pub fn verify_provider(mut cx: FunctionContext) -> JsResult<JsUndefined> {
_ => ()
};

let publish = match config.get(&mut cx, "publishVerificationResult") {
Ok(publish) => match publish.downcast::<JsBoolean>() {
Ok(publish) => publish.value(),
Err(_) => {
warn!("publishVerificationResult must be a boolean value. Ignoring it");
false
}
},
_ => false
};

let provider_version = match config.get(&mut cx, "providerVersion") {
Ok(provider_version) => match provider_version.downcast::<JsString>() {
Ok(provider_version) => Some(provider_version.value().to_string()),
Err(_) => if !provider_version.is_a::<JsUndefined>() {
println!(" {}", Red.paint("ERROR: providerVersion must be a string value"));
return cx.throw_error("providerVersion must be a string value")
} else {
None
}
},
_ => None
};

if publish && provider_version.is_none() {
println!(" {}", Red.paint("ERROR: providerVersion must be provided if publishing verification results in enabled (publishVerificationResult == true)"));
return cx.throw_error("providerVersion must be provided if publishing verification results in enabled (publishVerificationResult == true)")?
}

let provider_tags = match config.get(&mut cx, "providerVersionTag") {
Ok(provider_tags) => match provider_tags.downcast::<JsString>() {
Ok(provider_tag) => vec![ provider_tag.value().to_string() ],
Err(_) => match provider_tags.downcast::<JsArray>() {
Ok(provider_tags) => {
let mut tags = vec![];
for tag in provider_tags.to_vec(&mut cx)? {
match tag.downcast::<JsString>() {
Ok(val) => tags.push(val.value().to_string()),
Err(_) => {
println!(" {}", Red.paint("ERROR: providerVersionTag must be a string or array of strings"));
return cx.throw_error("providerVersionTag must be a string or array of strings")
}
}
};
tags
},
Err(_) => if !provider_tags.is_a::<JsUndefined>() {
println!(" {}", Red.paint("ERROR: providerVersionTag must be a string or array of strings"));
return cx.throw_error("providerVersionTag must be a string or array of strings")
} else {
vec![]
}
}
},
_ => vec![]
};

let filter_info = FilterInfo::None;
let consumers_filter: Vec<String> = vec![];
let options = VerificationOptions {
publish: false,
provider_version: None,
publish,
provider_version,
build_url: None,
request_filter,
provider_tags: vec![]
provider_tags
};

debug!("Starting background task");
Expand Down
16 changes: 13 additions & 3 deletions src/v3/pact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export class PactV3 {
return this
}

public withRequestBinaryFile(req: V3Request, contentType: string, file: string) {
public withRequestBinaryFile(
req: V3Request,
contentType: string,
file: string
) {
this.pact.addRequestBinaryFile(req, contentType, file)
return this
}
Expand All @@ -84,7 +88,11 @@ export class PactV3 {
return this
}

public withResponseBinaryFile(res: V3Response, contentType: string, file: string) {
public withResponseBinaryFile(
res: V3Response,
contentType: string,
file: string
) {
this.pact.addResponseBinaryFile(res, contentType, file)
return this
}
Expand All @@ -99,7 +107,9 @@ export class PactV3 {
return this
}

public executeTest<T>(testFn: (mockServer: V3MockServer) => Promise<T>): Promise<T> {
public executeTest<T>(
testFn: (mockServer: V3MockServer) => Promise<T>
): Promise<T> {
const result = this.pact.executeTest(testFn)
if (result.testResult) {
return result.testResult
Expand Down

0 comments on commit fcbdb3e

Please sign in to comment.