blob: 4ec546a977d663e3436a1942ab661d003f454b1b [file] [log] [blame]
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from PB.recipe_modules.fuchsia.spec.examples.specs import ExampleSpec
from recipe_engine.config import Enum
from recipe_engine.recipe_api import Property
DEPS = [
"fuchsia/spec",
"fuchsia/status_check",
"recipe_engine/buildbucket",
"recipe_engine/properties",
]
PROPERTIES = {
"expected_revision": Property(
kind=str, help="the test revision that should be fetched", default=None
),
"expected_result": Property(
kind=Enum("success", "not_found", "parse_error"),
help="the expected result of trying to fetch the spec",
default="success",
),
}
TestProtoMessage = ExampleSpec(value="example_value")
def RunSteps(api, expected_revision, expected_result):
if expected_result == "success":
expect_success(api, expected_revision)
elif expected_result == "not_found":
expect_not_found_error(api)
elif expected_result == "parse_error":
expect_parse_error(api)
else: # pragma: no cover
raise Exception("invalid expected result %s" % expected_result)
def expect_success(api, expected_revision=None):
message, revision = api.spec.get_spec_revision(
spec_remote="https://fuchsia.googlesource.com/fuchsia",
spec_dir="specs",
Type=ExampleSpec,
)
assert message == TestProtoMessage, message
expected_revision = expected_revision or "deadbeef"
assert revision == expected_revision, "actual rev:%s, expected:%s" % (
revision,
expected_revision,
)
message2, _ = api.spec.get_spec_revision(
spec_remote="https://fuchsia.googlesource.com/fuchsia",
spec_dir="specs",
Type=ExampleSpec,
spec_revision=revision,
)
assert message2 == message
def expect_not_found_error(api):
_expect_exception(api, api.spec.NotFoundError)
def expect_parse_error(api):
_expect_exception(api, api.spec.ParseError)
def _expect_exception(api, exception_type):
try:
api.spec.get_spec_revision(
spec_remote="https://fuchsia.googlesource.com/fuchsia",
spec_dir="specs",
Type=ExampleSpec,
)
except exception_type:
pass
else: # pragma: no cover
assert False, "loading spec should have raised %r" % exception_type
def GenTests(api):
def example_build():
return api.buildbucket.ci_build(
git_repo="https://fuchsia.googlesource.com/project", revision="deadbeef1",
)
yield (
api.status_check.test("spec_file_not_found")
+ api.properties(expected_result="not_found")
+ example_build()
+ api.spec.spec_not_found()
)
yield (
api.status_check.test("fatal_error", status="infra_failure")
+ example_build()
+ api.step_data("build_init", retcode=1)
)
yield (
api.status_check.test("spec_file_is_empty")
+ api.properties(expected_result="parse_error")
+ example_build()
+ api.spec.spec_loaded_ok(ExampleSpec())
)
yield (
api.status_check.test("parse_error")
+ api.properties(expected_result="parse_error")
+ example_build()
+ api.spec.spec_parse_error()
)
yield (
api.status_check.test("spec_file_is_ok")
+ example_build()
+ api.spec.spec_loaded_ok(TestProtoMessage)
+ api.spec.spec_loaded_ok(TestProtoMessage, step_name="build_init (2)")
)
yield (
api.status_check.test("subbuild")
+ api.buildbucket.ci_build(
builder="foo-subbuild",
git_repo="https://fuchsia.googlesource.com/project",
revision="deadbeef1",
)
+ api.spec.spec_loaded_ok(TestProtoMessage)
+ api.spec.spec_loaded_ok(TestProtoMessage, step_name="build_init (2)")
)
# use gitiles_commit.id if project is same as spec_remote
yield (
api.status_check.test("spec_remote_change")
+ api.buildbucket.ci_build(
builder="foo-subbuild",
git_repo="https://fuchsia.googlesource.com/fuchsia",
revision="deadbeef2",
)
+ api.properties(expected_revision="deadbeef2")
+ api.spec.spec_loaded_ok(TestProtoMessage)
+ api.spec.spec_loaded_ok(TestProtoMessage, step_name="build_init (2)")
)