Skip to content

Commit

Permalink
tests: add system tests for OS Config service v1 (#19)
Browse files Browse the repository at this point in the history
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-os-config/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

Tested by running `export PROJECT_ID="..."` then `nox -s system-3.7`.
  • Loading branch information
wj-chen authored Sep 17, 2020
1 parent 9e46244 commit 5327c7e
Showing 1 changed file with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright 2020 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
#
# https://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 os
import uuid

from google.cloud.osconfig_v1.services.os_config_service import OsConfigServiceClient
from google.cloud.osconfig_v1.types import patch_deployments
from google.cloud.osconfig_v1.types import patch_jobs
from google.protobuf import timestamp_pb2 as timestamp # type: ignore


class TestOsConfigServiceV1(object):
def test_patch_job(self):
project_id = os.environ["PROJECT_ID"]
client = OsConfigServiceClient()

# ExecutePatchJob
request = patch_jobs.ExecutePatchJobRequest(
parent=f"projects/{project_id}",
description="Python Client Library System Test",
instance_filter=patch_jobs.PatchInstanceFilter(all=True),
)
patch_job = client.execute_patch_job(request)
assert patch_job is not None

# GetPatchJob
request = patch_jobs.GetPatchJobRequest(name=patch_job.name)
patch_job = client.get_patch_job(request)
assert patch_job.description == "Python Client Library System Test"

# ListPatchJobInstanceDetails
request = patch_jobs.ListPatchJobInstanceDetailsRequest(parent=patch_job.name)
response = client.list_patch_job_instance_details(request)
assert len(response.patch_job_instance_details) >= 0

# CancelPatchJob
request = patch_jobs.CancelPatchJobRequest(name=patch_job.name)
patch_job = client.cancel_patch_job(request)
assert patch_job.state == patch_jobs.PatchJob.State.CANCELED

# ListPatchJobs
request = patch_jobs.ListPatchJobsRequest(parent=f"projects/{project_id}")
response = client.list_patch_jobs(request)
assert response.patch_jobs

def test_patch_deployment(self):
project_id = os.environ["PROJECT_ID"]
client = OsConfigServiceClient()

patch_deployment = patch_deployments.PatchDeployment(
instance_filter=patch_jobs.PatchInstanceFilter(all=True),
one_time_schedule=patch_deployments.OneTimeSchedule(
execute_time=timestamp.Timestamp(seconds=200000000000)
),
)
patch_deployment_id = "python-client-library-test-" + str(uuid.uuid1())
patch_deployment_name = (
f"projects/{project_id}/patchDeployments/{patch_deployment_id}"
)

# CreatePatchDeploymentRequest
request = patch_deployments.CreatePatchDeploymentRequest(
parent=f"projects/{project_id}",
patch_deployment_id=patch_deployment_id,
patch_deployment=patch_deployment,
)
patch_deployment = client.create_patch_deployment(request)
assert patch_deployment_id in patch_deployment.name

# GetPatchDeployment
request = patch_deployments.GetPatchDeploymentRequest(
name=patch_deployment_name
)
patch_deployment = client.get_patch_deployment(request)
assert patch_deployment_id in patch_deployment.name

# ListPatchDeployments
request = patch_deployments.ListPatchDeploymentsRequest(
parent=f"projects/{project_id}"
)
response = client.list_patch_deployments(request)
assert response.patch_deployments

# DeletePatchDeployment
request = patch_deployments.DeletePatchDeploymentRequest(
name=patch_deployment_name
)
client.delete_patch_deployment(request)

0 comments on commit 5327c7e

Please sign in to comment.