|
| 1 | +// Copyright 2025 Google LLC. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +using Google.Cloud.PubSub.V1; |
| 16 | +using Google.Protobuf.WellKnownTypes; |
| 17 | +using System; |
| 18 | +using Xunit; |
| 19 | + |
| 20 | +[Collection(nameof(PubsubFixture))] |
| 21 | +public class CreateTopicWithCloudStorageIngestionTest |
| 22 | +{ |
| 23 | + private readonly PubsubFixture _pubsubFixture; |
| 24 | + private readonly CreateTopicWithCloudStorageIngestionSample _createTopicWithCloudStorageIngestionSample; |
| 25 | + |
| 26 | + public CreateTopicWithCloudStorageIngestionTest(PubsubFixture pubsubFixture) |
| 27 | + { |
| 28 | + _pubsubFixture = pubsubFixture; |
| 29 | + _createTopicWithCloudStorageIngestionSample = new CreateTopicWithCloudStorageIngestionSample(); |
| 30 | + } |
| 31 | + |
| 32 | + [Fact] |
| 33 | + public void CreateTopicWithCloudStorageIngestion() |
| 34 | + { |
| 35 | + string topicId = _pubsubFixture.RandomTopicId(); |
| 36 | + string bucket = _pubsubFixture.RandomName("Bucket"); |
| 37 | + string inputFormat = "text"; |
| 38 | + string textDelimiter = "\n"; |
| 39 | + string matchGlob = "**.txt"; |
| 40 | + string minimumObjectCreateTime = "1970-01-01T00:00:00Z"; |
| 41 | + Topic createdTopic = _createTopicWithCloudStorageIngestionSample.CreateTopicWithCloudStorageIngestion(_pubsubFixture.ProjectId, topicId, bucket, inputFormat, textDelimiter, matchGlob, minimumObjectCreateTime); |
| 42 | + |
| 43 | + // Confirm that the created topic and topic retrieved by ID are equal |
| 44 | + Topic retrievedTopic = _pubsubFixture.GetTopic(topicId); |
| 45 | + Assert.Equal(createdTopic, retrievedTopic); |
| 46 | + |
| 47 | + // Confirm that all Cloud Storage Ingestion params are equal to expected values |
| 48 | + Assert.Equal(bucket, createdTopic.IngestionDataSourceSettings.CloudStorage.Bucket); |
| 49 | + Assert.NotNull(createdTopic.IngestionDataSourceSettings.CloudStorage.TextFormat); |
| 50 | + Assert.Equal(textDelimiter, createdTopic.IngestionDataSourceSettings.CloudStorage.TextFormat.Delimiter); |
| 51 | + Assert.Equal(matchGlob, createdTopic.IngestionDataSourceSettings.CloudStorage.MatchGlob); |
| 52 | + Assert.Equal(Timestamp.FromDateTime(DateTime.Parse(minimumObjectCreateTime)), createdTopic.IngestionDataSourceSettings.CloudStorage.MinimumObjectCreateTime); |
| 53 | + } |
| 54 | +} |
0 commit comments