Skip to content

Commit

Permalink
update tests to pre-install the az containerapp extension
Browse files Browse the repository at this point in the history
  • Loading branch information
smurawski authored Jun 2, 2022
1 parent 404e60f commit 75b87d6
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 183 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
from azure.cli.testsdk import (ScenarioTest)

TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))


def write_test_file(filename, content):
test_file = open(filename, "w", encoding='utf-8')
_ = test_file.write(content)
test_file.close()


def clean_up_test_file(filename):
if os.path.exists(filename):
os.remove(filename)


class ContainerappComposePreviewScenarioTest(ScenarioTest):
def setUp(self):
self.cmd("extension add --name containerapp")
return super().setUp()
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import unittest # pylint: disable=unused-import

from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)
from azure.cli.testsdk import (ResourceGroupPreparer)
from azure.cli.testsdk.decorators import serial_test
from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import
write_test_file,
clean_up_test_file,
TEST_DIR)


TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))


class ContainerappComposePreviewScenarioTest(ScenarioTest):
class ContainerappComposeBaseScenarioTest(ContainerappComposePreviewScenarioTest):

@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_create_basic_no_existing_resources(self, resource_group):
compose_text = """
Expand All @@ -22,9 +24,7 @@ def test_containerapp_compose_create_basic_no_existing_resources(self, resource_
image: smurawski/printenv:latest
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -42,5 +42,4 @@ def test_containerapp_compose_create_basic_no_existing_resources(self, resource_
self.check('[] | length(@)', 1),
])

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import unittest # pylint: disable=unused-import

from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)
from azure.cli.testsdk import (ResourceGroupPreparer)
from azure.cli.testsdk.decorators import serial_test
from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import
write_test_file,
clean_up_test_file,
TEST_DIR)


TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))


class ContainerappComposePreviewCommandScenarioTest(ScenarioTest):
class ContainerappComposePreviewCommandScenarioTest(ContainerappComposePreviewScenarioTest):
@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_with_command_string(self, resource_group):
compose_text = """
Expand All @@ -24,9 +26,7 @@ def test_containerapp_compose_with_command_string(self, resource_group):
- "5000"
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -43,9 +43,9 @@ def test_containerapp_compose_with_command_string(self, resource_group):
self.check('[?name==`foo`].properties.template.containers[0].command[0]', "['echo \"hello world\"']"),
])

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)

@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_with_command_list(self, resource_group):
compose_text = """
Expand All @@ -57,9 +57,7 @@ def test_containerapp_compose_with_command_list(self, resource_group):
- "5000"
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -76,9 +74,9 @@ def test_containerapp_compose_with_command_list(self, resource_group):
self.check('[?name==`foo`].properties.template.containers[0].command[0]', "['echo \"hello world\"']"),
])

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)

@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_with_command_list_and_entrypoint(self, resource_group):
compose_text = """
Expand All @@ -91,9 +89,7 @@ def test_containerapp_compose_with_command_list_and_entrypoint(self, resource_gr
- "5000"
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -111,5 +107,4 @@ def test_containerapp_compose_with_command_list_and_entrypoint(self, resource_gr
self.check('[?name==`foo`].properties.template.containers[0].args[0]', "['echo \"hello world\"']"),
])

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import unittest # pylint: disable=unused-import

from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)
from azure.cli.testsdk import (ResourceGroupPreparer)
from azure.cli.testsdk.decorators import serial_test
from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import
write_test_file,
clean_up_test_file,
TEST_DIR)


TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))


class ContainerappComposePreviewEnvironmentSettingsScenarioTest(ScenarioTest):
class ContainerappComposePreviewEnvironmentSettingsScenarioTest(ContainerappComposePreviewScenarioTest):
@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_create_with_environment(self, resource_group):
compose_text = """
Expand All @@ -25,9 +27,7 @@ def test_containerapp_compose_create_with_environment(self, resource_group):
- BAZ="snafu"
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -49,11 +49,11 @@ def test_containerapp_compose_create_with_environment(self, resource_group):
self.check('[?name==`foo`].properties.template.containers[0].env[2].value', ['"snafu"'])
])

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)


class ContainerappComposePreviewEnvironmentSettingsExpectedExceptionScenarioTest(ScenarioTest):
class ContainerappComposePreviewEnvironmentSettingsExpectedExceptionScenarioTest(ContainerappComposePreviewScenarioTest): # pylint: disable=line-too-long
@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_create_with_environment_prompt(self, resource_group):
compose_text = """
Expand All @@ -64,9 +64,7 @@ def test_containerapp_compose_create_with_environment_prompt(self, resource_grou
- LOREM=
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -83,5 +81,4 @@ def test_containerapp_compose_create_with_environment_prompt(self, resource_grou
# This test fails because prompts are not supported in NoTTY environments
self.cmd(command_string, expect_failure=True)

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import unittest # pylint: disable=unused-import

from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)
from azure.cli.testsdk import (ResourceGroupPreparer)
from azure.cli.testsdk.decorators import serial_test
from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import
write_test_file,
clean_up_test_file,
TEST_DIR)


TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))


class ContainerappComposePreviewIngressScenarioTest(ScenarioTest):
class ContainerappComposePreviewIngressScenarioTest(ContainerappComposePreviewScenarioTest):
@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_create_with_ingress_external(self, resource_group):
compose_text = """
Expand All @@ -22,9 +24,7 @@ def test_containerapp_compose_create_with_ingress_external(self, resource_group)
ports: 8080:80
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -42,11 +42,11 @@ def test_containerapp_compose_create_with_ingress_external(self, resource_group)
self.check('[?name==`foo`].properties.configuration.ingress.external', [True]),
])

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)


class ContainerappComposePreviewIngressInternalScenarioTest(ScenarioTest):
class ContainerappComposePreviewIngressInternalScenarioTest(ContainerappComposePreviewScenarioTest):
@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_create_with_ingress_internal(self, resource_group):
compose_text = """
Expand All @@ -57,9 +57,7 @@ def test_containerapp_compose_create_with_ingress_internal(self, resource_group)
- "3000"
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -77,11 +75,11 @@ def test_containerapp_compose_create_with_ingress_internal(self, resource_group)
self.check('[?name==`foo`].properties.configuration.ingress.external', [False]),
])

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)


class ContainerappComposePreviewIngressBothScenarioTest(ScenarioTest):
class ContainerappComposePreviewIngressBothScenarioTest(ContainerappComposePreviewScenarioTest):
@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_create_with_ingress_both(self, resource_group):
compose_text = """
Expand All @@ -93,9 +91,7 @@ def test_containerapp_compose_create_with_ingress_both(self, resource_group):
- "5000"
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -113,11 +109,11 @@ def test_containerapp_compose_create_with_ingress_both(self, resource_group):
self.check('[?name==`foo`].properties.configuration.ingress.external', [True]),
])

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)


class ContainerappComposePreviewIngressPromptScenarioTest(ScenarioTest):
class ContainerappComposePreviewIngressPromptScenarioTest(ContainerappComposePreviewScenarioTest):
@serial_test()
@ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus')
def test_containerapp_compose_create_with_ingress_prompt(self, resource_group):
compose_text = """
Expand All @@ -134,9 +130,7 @@ def test_containerapp_compose_create_with_ingress_prompt(self, resource_group):
- "443"
"""
compose_file_name = f"{self._testMethodName}_compose.yml"
docker_compose_file = open(compose_file_name, "w", encoding='utf-8')
_ = docker_compose_file.write(compose_text)
docker_compose_file.close()
write_test_file(compose_file_name, compose_text)

self.kwargs.update({
'environment': self.create_random_name(prefix='containerapp-compose', length=24),
Expand All @@ -153,5 +147,4 @@ def test_containerapp_compose_create_with_ingress_prompt(self, resource_group):
# This test fails because prompts are not supported in NoTTY environments
self.cmd(command_string, expect_failure=True)

if os.path.exists(compose_file_name):
os.remove(compose_file_name)
clean_up_test_file(compose_file_name)
Loading

0 comments on commit 75b87d6

Please sign in to comment.