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

Fixed the shared key creds issue. #6

Merged
merged 1 commit into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -89,8 +89,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 @@ -226,7 +225,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 @@ -263,7 +262,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 @@ -296,7 +294,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 @@ -452,90 +453,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