blob: 747f30cef9cf0525130bd66f86f8dc3206c1956f [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 recipe_engine import post_process
from recipe_engine.recipe_api import Property
from RECIPE_MODULES.fuchsia.release.api import ReleaseVersion
DEPS = [
"fuchsia/release",
"recipe_engine/properties",
]
PROPERTIES = {
"major": Property(kind=int, help="Major number."),
"date": Property(kind=str, help="Date as YYYYMMDD."),
"release": Property(kind=int, help="Release number."),
"candidate": Property(kind=int, help="Candidate number."),
}
def RunSteps(api, major, date, release, candidate):
version_a = ReleaseVersion(
major=major, date=date, release=release, candidate=candidate
)
version_string = str(version_a)
version_b = ReleaseVersion.from_string(version_string)
assert version_a == version_b
version_a.candidate += 1
assert version_a > version_b, 'version with larger "candidate" should be greater'
version_b.release += 1
assert version_b > version_a, 'version with larger "release" should be greater'
version_a.date += 1
assert version_a > version_b, 'version with larger "date" should be greater'
version_b.major += 1
assert version_b > version_a, 'version with larger "major" should be greater'
def GenTests(api):
def test(name, fail=False, major=0, date="20191019", release=0, candidate=1):
res = api.test(name, status="INFRA_FAILURE" if fail else "SUCCESS")
res += api.properties(
major=major, date=date, release=release, candidate=candidate
)
if fail:
res += api.expect_exception("AssertionError")
# Use DropExpectation to avoid generating expectation files, since the
# expectation files for this recipe would contain only stack traces.
# Stack traces are brittle because they include recipe file line
# numbers, and they're not very helpful to include in expectation files.
res += api.post_process(post_process.DropExpectation)
return res
yield test("pass")
yield test("negative_major", fail=True, major=-1)
yield test("short_date", fail=True, date="2019")
yield test("long_date", fail=True, date="2020191019209")
yield test("negative_release", fail=True, release=-1)
yield test("zero_candidate", fail=True, candidate=0)
yield test("negative_candidate", fail=True, candidate=-1)