blob: 99e0b2e82c24d2320498ed259764007a6d686bd2 [file] [log] [blame]
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
DEPS = [
'flutter/common',
'recipe_engine/file',
'recipe_engine/path',
'recipe_engine/properties',
]
def RunSteps(api):
method = api.properties['method']
if method == 'is_release_candidate_branch':
assert api.common.is_release_candidate_branch(
api.properties['branch']
) == api.properties['expectation']
elif method == 'branch_ref_to_branch_name':
ref = api.properties['branch_name']
expectation = api.properties['expectation']
assert api.common.branch_ref_to_branch_name(ref) == expectation
elif method == 'get_release_candidate_branch_from_checkout':
checkout = api.properties['checkout']
expectation = api.properties['expectation']
actual = api.common.get_release_candidate_branch_from_checkout(checkout)
assert actual == expectation, "'%s' did not match expected ('%s') version" % (
actual, expectation
)
else:
raise AssertionError(
f'Malformed test property: key "method" was "{method}". ' +
'You probably need to add this method to the RunSteps function.'
)
def GenTests(api):
checkout_path = api.path.start_dir / 'flutter'
yield api.test(
'is_release_candidate_branch detects non-release branch',
api.properties(
**{
'method': 'is_release_candidate_branch',
'branch': 'main',
'expectation': False,
}
)
)
yield api.test(
'is_release_candidate_branch detects release branch',
api.properties(
**{
'method': 'is_release_candidate_branch',
'branch': 'flutter-10.37-candidate.1001',
'expectation': True,
}
)
)
yield api.test(
'branch_ref_to_branch_name_works',
api.properties(
method='branch_ref_to_branch_name',
branch_name='refs/heads/foo_bar',
expectation='foo_bar',
)
)
yield api.test(
'catches_invalid_method_property',
api.properties(method=None),
api.expect_exception('AssertionError'),
)
version_path = checkout_path / 'bin/internal/release-candidate-branch.version'
yield api.test(
'get_release_candidate_branch_from_checkout',
api.path.exists(version_path),
api.step_data(
'read release-candidate-branch.version',
api.file.read_text('flutter-3.34-candidate.0',),
),
api.properties(
method='get_release_candidate_branch_from_checkout',
checkout=checkout_path,
expectation='flutter-3.34-candidate.0',
)
)
yield api.test(
'get_release_candidate_branch_from_checkout_missing_file',
api.properties(
method='get_release_candidate_branch_from_checkout',
checkout=checkout_path,
expectation=None,
)
)