Skip to content

Commit

Permalink
refactor: fix typos + add uats to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
saranyailla committed Feb 24, 2022
1 parent d42138a commit 2e58fb3
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion gdk/commands/component/PublishCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def create_bucket(self, bucket, region):
if self.bucket_exists_in_same_region(bucket, region):
logging.info("Not creating an artifacts bucket as it already exists.")
return
logging.error("Cannot create the artifacts bucket '{}' as it is already owned by you in other region.")
logging.error(f"Cannot create the artifacts bucket '{bucket}' as it is already owned by you in other region.")
raise Exception(e)
except Exception as e:
logging.error("Failed to create the bucket '{}' in region '{}'".format(bucket, region))
Expand Down
2 changes: 1 addition & 1 deletion gdk/commands/component/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def init(d_args):
try:
InitCommand(d_args).run()
except Exception as e:
raise Exception(f"Could not initialze the project due to the following error.\n{e}")
raise Exception(f"Could not initialize the project due to the following error.\n{e}")


def build(d_args):
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/gdk/components/test_integ_InitCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_init_run_with_conflicting_args(self):
with pytest.raises(Exception) as e:
parse_args_actions.run_command(CLIParser.cli_parser.parse_args(["component", "init", "--repository", "dummy"]))

assert "Could not initialze the project due to the following error." in e.value.args[0]
assert "Could not initialize the project due to the following error." in e.value.args[0]

assert mock_is_directory_empty.call_count == 0
assert mock_init_with_template.call_count == 0
Expand Down
10 changes: 5 additions & 5 deletions uat/t_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import boto3


def update_config(config_file, component_name, region, bucket, author):
def update_config(config_file, component_name, region, bucket, author, version="NEXT_PATCH"):
# Update gdk-config file mandatory field like region.
with open(str(config_file), "r") as f:
config = json.loads(f.read())
config["component"][component_name]["author"] = author
config["component"][component_name]["publish"]["region"] = region
config["component"][component_name]["publish"]["bucket"] = bucket
config["component"][component_name]["version"] = version
with open(str(config_file), "w") as f:
f.write(json.dumps(config))

Expand Down Expand Up @@ -51,10 +52,9 @@ def get_version_created(recipes_path, component_name):
for f in Path(recipes_path).iterdir():
if component_name in str(f.resolve()):
file_name = f.name
break
split_file_name = file_name.split(f"{component_name}-")
split_for_version = split_file_name[1].split(".yaml")[0]
return split_for_version
split_file_name = file_name.split(f"{component_name}-")
split_for_version = split_file_name[1].split(".yaml")[0]
return split_for_version


def create_s3_client(region):
Expand Down
12 changes: 3 additions & 9 deletions uat/test_uat_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def test_build_template_zip(change_test_dir, gdk_cli):
component_name = "com.example.PythonHelloWorld"
region = "us-east-1"
# Check if init downloads templates with necessary files.
check_init_template = gdk_cli.run(
["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"]
)
check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"])
assert check_init_template.returncode == 0
assert Path(path_HelloWorld).joinpath("recipe.yaml").resolve().exists()
config_file = Path(path_HelloWorld).joinpath("gdk-config.json").resolve()
Expand Down Expand Up @@ -48,9 +46,7 @@ def test_build_template_zip_fail_with_no_artifact(change_test_dir, gdk_cli):
component_name = "com.example.PythonHelloWorld"
region = "us-east-1"
# Check if init downloads templates with necessary files.
check_init_template = gdk_cli.run(
["component", "init", "-t", "HelloWorld", "-l", "python", "-n", dir_name]
)
check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", dir_name])
assert check_init_template.returncode == 0
assert Path(dir_path).joinpath("recipe.yaml").resolve().exists()
config_file = Path(dir_path).joinpath("gdk-config.json").resolve()
Expand Down Expand Up @@ -78,9 +74,7 @@ def test_build_template_maven(change_test_dir, gdk_cli):
component_name = "com.example.JavaHelloWorld"
region = "us-east-1"
# Check if init downloads templates with necessary files.
check_init_template = gdk_cli.run(
["component", "init", "-t", "HelloWorld", "-l", "java", "-n", "HelloWorld"]
)
check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "java", "-n", "HelloWorld"])
assert check_init_template.returncode == 0
assert Path(path_HelloWorld).joinpath("recipe.yaml").resolve().exists()
config_file = Path(path_HelloWorld).joinpath("gdk-config.json").resolve()
Expand Down
35 changes: 26 additions & 9 deletions uat/test_uat_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ def test_init_template(change_test_dir, gdk_cli):
def test_init_template_with_new_directory(change_test_dir, gdk_cli):
dir = "test-dir"
dirpath = Path(change_test_dir).joinpath(dir)
check_init_template = gdk_cli.run(
["component", "init", "-t", "HelloWorld", "-l", "python", "-n", dir]
)
check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", dir])
assert check_init_template.returncode == 0
assert Path(dirpath).joinpath("recipe.yaml").resolve().exists()
assert Path(dirpath).joinpath("gdk-config.json").resolve().exists()


def test_init_repository(change_test_dir, gdk_cli):
dirpath = Path(change_test_dir)
check_init_repo = gdk_cli.run(
["component", "init", "-r", "aws-greengrass-labs-database-influxdb"]
)
check_init_repo = gdk_cli.run(["component", "init", "-r", "aws-greengrass-labs-database-influxdb"])
assert check_init_repo.returncode == 0
assert Path(dirpath).joinpath("recipe.yaml").exists()
assert Path(dirpath).joinpath("gdk-config.json").exists()
Expand All @@ -39,9 +35,30 @@ def test_init_repository(change_test_dir, gdk_cli):
def test_init_repository_with_new_dir(change_test_dir, gdk_cli):
dir = "test-dir"
dirpath = Path(change_test_dir).joinpath(dir)
check_init_repo = gdk_cli.run(
["component", "init", "-r", "aws-greengrass-labs-database-influxdb", "-n", dir]
)
check_init_repo = gdk_cli.run(["component", "init", "-r", "aws-greengrass-labs-database-influxdb", "-n", dir])
assert check_init_repo.returncode == 0
assert Path(dirpath).joinpath("recipe.yaml").exists()
assert Path(dirpath).joinpath("gdk-config.json").exists()


def test_init_repository_not_exists(change_test_dir, gdk_cli):
check_init_repo = gdk_cli.run(["component", "init", "-r", "repo-not-exists"])
assert check_init_repo.returncode == 1
assert (
"Could not find the component repository 'repo-not-exists' in Greengrass Software Catalog." in check_init_repo.output
)


def test_init_template_not_exists(change_test_dir, gdk_cli):
check_init_temp = gdk_cli.run(["component", "init", "-t", "temp-not-exists", "-l", "python"])
assert check_init_temp.returncode == 1
assert (
"Could not find the component template 'temp-not-exists-python' in Greengrass Software Catalog."
in check_init_temp.output
)


def test_init_incomplete_args(change_test_dir, gdk_cli):
check_init = gdk_cli.run(["component", "init"])
assert check_init.returncode == 1
assert "Could not initialize the project as the arguments passed are invalid." in check_init.output
6 changes: 6 additions & 0 deletions uat/test_uat_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ def test_list_template(gdk_cli):
def test_list_repository(gdk_cli):
check_list_template = gdk_cli.run(["component", "list", "--repository"])
assert "aws-greengrass-labs-database-influxdb" in check_list_template.output


def test_list_incomplete_args(gdk_cli):
check_list_template = gdk_cli.run(["component", "list"])
assert check_list_template.returncode == 1
assert "Could not list the components as the command arguments are invalid." in check_list_template.output
15 changes: 6 additions & 9 deletions uat/test_uat_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ def test_publish_template_zip(change_test_dir, gdk_cli):
bucket = "gdk-cli-uat"
author = "gdk-cli-uat"
# Check if init downloads templates with necessary files.
check_init_template = gdk_cli.run(
["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"]
)
check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"])
assert check_init_template.returncode == 0
assert Path(path_HelloWorld).joinpath("recipe.yaml").resolve().exists()
config_file = Path(path_HelloWorld).joinpath("gdk-config.json").resolve()
Expand Down Expand Up @@ -44,17 +42,15 @@ def test_publish_template_zip(change_test_dir, gdk_cli):
t_utils.clean_up_aws_resources(component_name, t_utils.get_version_created(recipes_path, component_name), region)


def test_publish_without_build_template_zip(change_test_dir, gdk_cli):
def test_publish_without_build_template_zip_with_bucket_arg(change_test_dir, gdk_cli):
# Recipe contains HelloWorld.zip artifact. So, create HelloWorld directory inside temporary directory.
path_HelloWorld = Path(change_test_dir).joinpath("HelloWorld")
component_name = "com.example.PythonHelloWorld"
region = "us-east-1"
bucket = "gdk-cli-uat"
author = "gdk-cli-uat"
# Check if init downloads templates with necessary files.
check_init_template = gdk_cli.run(
["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"]
)
check_init_template = gdk_cli.run(["component", "init", "-t", "HelloWorld", "-l", "python", "-n", "HelloWorld"])
assert check_init_template.returncode == 0
assert Path(path_HelloWorld).joinpath("recipe.yaml").resolve().exists()
config_file = Path(path_HelloWorld).joinpath("gdk-config.json").resolve()
Expand All @@ -64,8 +60,9 @@ def test_publish_without_build_template_zip(change_test_dir, gdk_cli):
t_utils.update_config(config_file, component_name, region, bucket, author)

os.chdir(path_HelloWorld)

check_publish_component = gdk_cli.run(["component", "publish"])
# Pass in bucket name as arg
bucket_arg = "{}-{}-{}".format(bucket, region, t_utils.get_acc_num(region))
check_publish_component = gdk_cli.run(["component", "publish", "-b", bucket_arg])
assert check_publish_component.returncode == 0
assert Path(path_HelloWorld).joinpath("zip-build").resolve().exists()
assert Path(path_HelloWorld).joinpath("greengrass-build").resolve().exists()
Expand Down

0 comments on commit 2e58fb3

Please sign in to comment.