Migrate PubSub tests

This commit is contained in:
Julio Castillo 2023-04-14 17:14:02 +02:00
parent 1927b138d6
commit 01b9921f5c
10 changed files with 195 additions and 108 deletions

View File

@ -16,7 +16,7 @@ module "pubsub" {
"roles/pubsub.subscriber" = ["user:user1@example.com"]
}
}
# tftest modules=1 resources=3
# tftest modules=1 resources=3 inventory=simple.yaml
```
### Topic with schema
@ -48,7 +48,7 @@ module "topic_with_schema" {
})
}
}
# tftest modules=1 resources=2
# tftest modules=1 resources=2 inventory=schema.yaml
```
### Subscriptions
@ -74,7 +74,7 @@ module "pubsub" {
}
}
}
# tftest modules=1 resources=3
# tftest modules=1 resources=3 inventory=subscriptions.yaml
```
### Push subscriptions

View File

@ -0,0 +1,31 @@
# Copyright 2023 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.
values:
module.pubsub.google_pubsub_subscription.default["test-bigquery"]:
bigquery_config:
- drop_unknown_fields: true
table: my_project_id:my_dataset.my_table
use_topic_schema: true
write_metadata: false
name: test-bigquery
project: my-project
topic: my-topic
module.pubsub.google_pubsub_topic.default:
name: my-topic
project: my-project
counts:
google_pubsub_subscription: 1
google_pubsub_topic: 1

View File

@ -0,0 +1,30 @@
# Copyright 2023 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.
values:
module.pubsub.google_pubsub_subscription.default["test-push"]:
name: test-push
project: my-project
push_config:
- attributes: null
oidc_token: []
push_endpoint: https://example.com/foo
topic: my-topic
module.pubsub.google_pubsub_topic.default:
name: my-topic
project: my-project
counts:
google_pubsub_subscription: 1
google_pubsub_topic: 1

View File

@ -0,0 +1,29 @@
# Copyright 2023 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.
values:
module.topic_with_schema.google_pubsub_schema.default[0]:
definition: '{"fields":[{"name":"StringField","type":"string"},{"name":"FloatField","type":"float"},{"name":"BooleanField","type":"boolean"}],"name":"Avro","type":"record"}'
name: my-topic-schema
project: my-project
type: AVRO
module.topic_with_schema.google_pubsub_topic.default:
name: my-topic
project: my-project
schema_settings:
- encoding: JSON
counts:
google_pubsub_schema: 1
google_pubsub_topic: 1

View File

@ -0,0 +1,36 @@
# Copyright 2023 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.
values:
module.pubsub.google_pubsub_topic.default:
name: my-topic
project: my-project
module.pubsub.google_pubsub_topic_iam_binding.default["roles/pubsub.subscriber"]:
condition: []
members:
- user:user1@example.com
project: my-project
role: roles/pubsub.subscriber
topic: my-topic
module.pubsub.google_pubsub_topic_iam_binding.default["roles/pubsub.viewer"]:
condition: []
members:
- group:foo@example.com
project: my-project
role: roles/pubsub.viewer
topic: my-topic
counts:
google_pubsub_topic: 1
google_pubsub_topic_iam_binding: 2

View File

@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -11,3 +11,17 @@
# 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.
values:
module.pubsub.google_pubsub_subscription_iam_binding.default["test-1.roles/pubsub.subscriber"]:
condition: []
members:
- user:user1@ludomagno.net
project: my-project
role: roles/pubsub.subscriber
subscription: test-1
counts:
google_pubsub_subscription: 1
google_pubsub_subscription_iam_binding: 1
google_pubsub_topic: 1

View File

@ -0,0 +1,51 @@
# Copyright 2023 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.
values:
module.pubsub.google_pubsub_subscription.default["test-pull"]:
bigquery_config: []
dead_letter_policy: []
enable_exactly_once_delivery: null
enable_message_ordering: null
filter: null
labels: null
message_retention_duration: 604800s
name: test-pull
project: my-project
push_config: []
retain_acked_messages: null
retry_policy: []
topic: my-topic
module.pubsub.google_pubsub_subscription.default["test-pull-override"]:
bigquery_config: []
dead_letter_policy: []
enable_exactly_once_delivery: null
enable_message_ordering: null
filter: null
labels:
test: override
message_retention_duration: 604800s
name: test-pull-override
project: my-project
push_config: []
retain_acked_messages: true
retry_policy: []
topic: my-topic
module.pubsub.google_pubsub_topic.default:
name: my-topic
project: my-project
counts:
google_pubsub_subscription: 2
google_pubsub_topic: 1

View File

@ -1,34 +0,0 @@
/**
* 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.
*/
module "test" {
source = "../../../../modules/pubsub"
project_id = "my-project"
regions = ["europe-west1"]
name = "test"
iam = {
"roles/pubsub.publisher" = ["user:me@example.com"]
}
subscriptions = {
test = null
}
subscription_iam = {
test = {
"roles/pubsub.subscriber" = ["user:me@example.com"]
}
}
labels = var.labels
}

View File

@ -1,20 +0,0 @@
/**
* 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.
*/
variable "labels" {
type = map(string)
default = {}
}

View File

@ -1,50 +0,0 @@
# 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.
import pytest
@pytest.fixture
def resources(plan_runner):
_, resources = plan_runner()
return resources
def test_resource_count(resources):
"Test number of resources created."
assert len(resources) == 4
def test_iam(resources):
"Test IAM binding resources."
bindings = [r['values'] for r in resources if r['type']
== 'google_pubsub_topic_iam_binding']
assert len(bindings) == 1
assert bindings[0]['role'] == 'roles/pubsub.publisher'
def test_subscriptions(resources):
"Test subscription resources."
subs = [r['values'] for r in resources if r['type']
== 'google_pubsub_subscription']
assert len(subs) == 1
assert set(s['name'] for s in subs) == set(['test'])
def test_subscription_iam(resources):
"Test subscription IAM binding resources."
bindings = [r['values'] for r in resources if r['type']
== 'google_pubsub_subscription_iam_binding']
assert len(bindings) == 1
assert set(b['role'] for b in bindings) == set(['roles/pubsub.subscriber'])