pubsub: add a test for message storage policy
@@ -495,3 +495,43 @@ func TestIntegration_Errors(t *testing.T) {
t.Errorf("got <%v>, want %s", err, want)
}
}
+
+func TestIntegration_MessageStoragePolicy(t *testing.T) {
+ // Verify that the message storage policy is populated.
+ if testing.Short() {
+ t.Skip("Integration tests skipped in short mode")
+ }
+ ctx := context.Background()
+ // The message storage policy depends on the Resource Location Restriction org policy.
+ // The usual testing project is in the google.com org, which has no resource location restrictions,
+ // so we will always see an empty MessageStoragePolicy. Use a project in another org that does
+ // have a restriction set ("us-east1").
+ projID := "ps-geofencing-test"
+ // We can use the same creds as always because the service account of the default testing project
+ // has permission to use the above project. This test will fail if a different service account
+ // is used for testing.
+ ts := testutil.TokenSource(ctx, ScopePubSub, ScopeCloudPlatform)
+ if ts == nil {
+ t.Skip("Integration tests skipped. See CONTRIBUTING.md for details")
+ }
+ client, err := NewClient(ctx, projID, option.WithTokenSource(ts))
+ if err != nil {
+ t.Fatalf("Creating client error: %v", err)
+ }
+ topic, err := client.CreateTopic(ctx, topicIDs.New())
+ if err != nil {
+ t.Fatalf("CreateTopic error: %v", err)
+ }
+ defer topic.Stop()
+ defer topic.Delete(ctx)
+
+ config, err := topic.Config(ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ got := config.MessageStoragePolicy.AllowedPersistenceRegions
+ want := []string{"us-east1"}
+ if !testutil.Equal(got, want) {
+ t.Errorf("got %v, want %v", got, want)
+ }
+}
