-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add skeleton implementation of GrpcStorageImpl#getServiceAccount (
#1384) * Add conversion for com.google.storage.v2.ServiceAccount * Add property test to ensure round trip decode -> endode -> decode succeeds * Add ServiceAccountArbitraryProvider
- Loading branch information
1 parent
a2e9b88
commit 96b6330
Showing
5 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
google-cloud-storage/src/test/java/com/google/cloud/storage/ServiceAccountPropertyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.storage; | ||
|
||
import static com.google.cloud.storage.JqwikTest.report; | ||
import static com.google.common.truth.Truth.assertThat; | ||
import static net.jqwik.api.providers.TypeUsage.of; | ||
|
||
import com.google.cloud.storage.Conversions.Codec; | ||
import net.jqwik.api.Example; | ||
import net.jqwik.api.ForAll; | ||
import net.jqwik.api.Property; | ||
|
||
final class ServiceAccountPropertyTest { | ||
|
||
@Example | ||
void edgeCases() { | ||
report(of(com.google.storage.v2.ServiceAccount.class)); | ||
} | ||
|
||
@Property | ||
void codecCanRoundTrip(@ForAll com.google.storage.v2.ServiceAccount sa) { | ||
Codec<ServiceAccount, com.google.storage.v2.ServiceAccount> codec = | ||
Conversions.grpc().serviceAccount(); | ||
ServiceAccount decode = codec.decode(sa); | ||
|
||
assertThat(decode.getEmail()).isEqualTo(sa.getEmailAddress()); | ||
|
||
com.google.storage.v2.ServiceAccount encode = codec.encode(decode); | ||
assertThat(encode).isEqualTo(sa); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...storage/src/test/java/com/google/cloud/storage/jqwik/ServiceAccountArbitraryProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.storage.jqwik; | ||
|
||
import com.google.storage.v2.ServiceAccount; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import net.jqwik.api.Arbitrary; | ||
import net.jqwik.api.providers.ArbitraryProvider; | ||
import net.jqwik.api.providers.TypeUsage; | ||
import net.jqwik.web.api.EmailArbitrary; | ||
import net.jqwik.web.api.Web; | ||
|
||
public final class ServiceAccountArbitraryProvider implements ArbitraryProvider { | ||
|
||
@Override | ||
public boolean canProvideFor(TypeUsage targetType) { | ||
return targetType.isOfType(ServiceAccount.class); | ||
} | ||
|
||
@Override | ||
public Set<Arbitrary<?>> provideFor(TypeUsage targetType, SubtypeProvider subtypeProvider) { | ||
EmailArbitrary emails = Web.emails(); | ||
return Collections.singleton( | ||
emails.map(e -> ServiceAccount.newBuilder().setEmailAddress(e).build())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters