Skip to content

Commit

Permalink
Merge pull request #6 from sima-zhu/dev_storage-tests
Browse files Browse the repository at this point in the history
Fixed the shared key creds issue.
  • Loading branch information
jianghaolu authored Jun 11, 2019
2 parents 2d68b76 + 1b8da8c commit 603a06f
Show file tree
Hide file tree
Showing 2 changed files with 436 additions and 83 deletions.
198 changes: 115 additions & 83 deletions storage/client/src/test/java/com/azure/storage/blob/APISpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ class APISpec extends Specification {
/*
URLs to various kinds of accounts.
*/
@Shared
static BlobServiceClient primaryServiceURL
BlobServiceClient primaryServiceURL

@Shared
static BlobServiceClient alternateServiceURL
Expand Down Expand Up @@ -231,7 +230,7 @@ class APISpec extends Specification {
new ListContainersOptions().withPrefix(containerPrefix))) {
ContainerClient containerURL = serviceURL.createContainerClient(c.name())
if (c.properties().leaseState().equals(LeaseStateType.LEASED)) {
containerURL.breakLease(0, null, null).blockingGet()
containerURL.breakLease(0, null, null)
}
containerURL.delete()
}
Expand Down Expand Up @@ -268,7 +267,6 @@ class APISpec extends Specification {
We'll let primary creds throw and crash if there are no credentials specified because everything else will fail.
*/
primaryCreds = getGenericCreds("PRIMARY_STORAGE_")
primaryServiceURL = getGenericServiceURL(primaryCreds)

/*
It's feasible someone wants to test a specific subset of tests, so we'll still attempt to create each of the
Expand Down Expand Up @@ -301,7 +299,10 @@ class APISpec extends Specification {

def setup() {
Assume.assumeTrue("The test only runs in Live mode.", getTestMode().equalsIgnoreCase(RECORD_MODE))
cu = primaryServiceURL.createContainerClient(generateContainerName())
String containerName = generateContainerName()

primaryServiceURL = getGenericServiceURL(primaryCreds)
cu = primaryServiceURL.createContainerClient(containerName)
cu.create()
}

Expand Down Expand Up @@ -457,90 +458,121 @@ class APISpec extends Specification {
to play too nicely with mocked objects and the complex reflection stuff on both ends made it more difficult to work
with than was worth it.
*/
def getStubResponse(int code, Class responseHeadersType) {
return new HttpResponse() {

@Override
int statusCode() {
return code
}

@Override
String headerValue(String s) {
return null
}

@Override
HttpHeaders headers() {
return new HttpHeaders()
}

@Override
Flux<ByteBuffer> body() {
return Flowable.empty()
}

@Override
Mono<byte[]> bodyAsByteArray() {
return null
}

@Override
Mono<String> bodyAsString() {
return null
}

@Override
Mono<String> bodyAsString(Charset charset) {
return null
}
}
}
// def getStubResponse(int code, Class responseHeadersType) {
// return new HttpResponse() {
//
// @Override
// int statusCode() {
// return code
// }
//
// @Override
// String headerValue(String s) {
// return null
// }
//
// @Override
// HttpHeaders headers() {
// return new HttpHeaders()
// }
//
// @Override
// Flux<ByteBuffer> body() {
// return Flowable.empty()
// }
//
// @Override
// Mono<byte[]> bodyAsByteArray() {
// return null
// }
//
// @Override
// Mono<String> bodyAsString() {
// return null
// }
//
// @Override
// Mono<String> bodyAsString(Charset charset) {
// return null
// }
//
// @Override
// Object deserializedHeaders() {
// def headers = responseHeadersType.getConstructor().newInstance()
//
// // If the headers have an etag method, we need to set it to prevent postProcessResponse from breaking.
// try {
// headers.getClass().getMethod("withETag", String.class).invoke(headers, "etag");
// }
// catch (NoSuchMethodException e) {
// // No op
// }
// return headers
// }
//
// @Override
// boolean isDecoded() {
// return true
// }
// }
// }

/*
This is for stubbing responses that will actually go through the pipeline and autorest code. Autorest does not seem
to play too nicely with mocked objects and the complex reflection stuff on both ends made it more difficult to work
with than was worth it. Because this type is just for BlobDownload, we don't need to accept a header type.
*/
def getStubResponseForBlobDownload(int code, Flux<ByteBuffer> body, String etag) {
return new HttpResponse() {

@Override
int statusCode() {
return code
}

@Override
String headerValue(String s) {
return null
}

@Override
HttpHeaders headers() {
return new HttpHeaders()
}

@Override
Flux<ByteBuffer> body() {
return body
}

@Override
Mono<byte[]> bodyAsByteArray() {
return null
}

@Override
Mono<String> bodyAsString() {
return null
}

@Override
Mono<String> bodyAsString(Charset charset) {
return null
}
}
}
// def getStubResponseForBlobDownload(int code, Flux<ByteBuffer> body, String etag) {
// return new HttpResponse() {
//
// @Override
// int statusCode() {
// return code
// }
//
// @Override
// String headerValue(String s) {
// return null
// }
//
// @Override
// HttpHeaders headers() {
// return new HttpHeaders()
// }
//
// @Override
// Flux<ByteBuffer> body() {
// return body
// }
//
// @Override
// Mono<byte[]> bodyAsByteArray() {
// return null
// }
//
// @Override
// Mono<String> bodyAsString() {
// return null
// }
//
// @Override
// Mono<String> bodyAsString(Charset charset) {
// return null
// }
//
// @Override
// Object deserializedHeaders() {
// def headers = new BlobDownloadHeaders()
// headers.withETag(etag)
// return headers
// }
//
// @Override
// boolean isDecoded() {
// return true
// }
// }
// }

def getContextStubPolicy(int successCode, Class responseHeadersType) {
return Mock(HttpPipelinePolicy) {
Expand Down
Loading

0 comments on commit 603a06f

Please sign in to comment.