2018-03-05 08:10:38 -06:00
|
|
|
# Copyright 2018 AT&T Intellectual Property. All other rights reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2018-04-03 21:19:52 +01:00
|
|
|
|
2018-03-05 08:10:38 -06:00
|
|
|
import click
|
|
|
|
import mock
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from pegleg import config
|
|
|
|
from pegleg.engine import lint
|
|
|
|
|
2018-06-25 10:43:43 -07:00
|
|
|
_SKIP_P003_REASON = """Currently broken with revisioned repositories
|
|
|
|
directory layout changes. The old pseudo-revision folders like 'v4.0' is
|
|
|
|
no longer relevant and so the lint logic for this rule needs to be updated.
|
|
|
|
For more information, see: https://storyboard.openstack.org/#!/story/2003762
|
|
|
|
"""
|
2018-03-05 08:10:38 -06:00
|
|
|
|
2018-09-14 08:08:21 -06:00
|
|
|
|
2018-03-05 08:10:38 -06:00
|
|
|
@mock.patch.object(lint, '_verify_deckhand_render', return_value=[])
|
|
|
|
@mock.patch.object(lint, '_verify_no_unexpected_files', return_value=[])
|
|
|
|
def test_lint_excludes_P001(*args):
|
|
|
|
exclude_lint = ['P001']
|
2018-06-25 10:43:43 -07:00
|
|
|
config.set_site_repo('../pegleg/site_yamls/')
|
2018-03-05 08:10:38 -06:00
|
|
|
|
2018-04-02 15:45:00 -05:00
|
|
|
code_1 = 'X001'
|
2018-03-05 08:10:38 -06:00
|
|
|
msg_1 = 'is a secret, but has unexpected storagePolicy: "cleartext"'
|
2018-04-02 15:45:00 -05:00
|
|
|
code_2 = 'X002'
|
2018-03-05 08:10:38 -06:00
|
|
|
msg_2 = 'test msg'
|
2018-04-02 15:45:00 -05:00
|
|
|
msgs = [(code_1, msg_1), (code_2, msg_2)]
|
2018-03-05 08:10:38 -06:00
|
|
|
|
2018-04-02 15:45:00 -05:00
|
|
|
with mock.patch.object(
|
|
|
|
lint, '_verify_file_contents', return_value=msgs) as mock_methed:
|
2018-03-05 08:10:38 -06:00
|
|
|
with pytest.raises(click.ClickException) as expected_exc:
|
|
|
|
results = lint.full(False, exclude_lint, [])
|
|
|
|
assert msg_1 in expected_exc
|
|
|
|
assert msg_2 in expected_exc
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch.object(lint, '_verify_no_unexpected_files', return_value=[])
|
|
|
|
def test_lint_excludes_P002(*args):
|
|
|
|
exclude_lint = ['P002']
|
2018-06-25 10:43:43 -07:00
|
|
|
config.set_site_repo('../pegleg/site_yamls/')
|
2018-04-02 15:45:00 -05:00
|
|
|
with mock.patch.object(
|
|
|
|
lint,
|
|
|
|
'_verify_deckhand_render',
|
|
|
|
return_value=[('P002', 'test message')]) as mock_method:
|
2018-03-05 08:10:38 -06:00
|
|
|
lint.full(False, exclude_lint, [])
|
2018-04-02 15:45:00 -05:00
|
|
|
mock_method.assert_called()
|
2018-03-05 08:10:38 -06:00
|
|
|
|
|
|
|
|
2018-06-25 10:43:43 -07:00
|
|
|
@pytest.mark.skip(reason=_SKIP_P003_REASON)
|
2018-03-05 08:10:38 -06:00
|
|
|
@mock.patch.object(lint, '_verify_deckhand_render', return_value=[])
|
|
|
|
def test_lint_excludes_P003(*args):
|
|
|
|
exclude_lint = ['P003']
|
2018-04-02 15:45:00 -05:00
|
|
|
with mock.patch.object(
|
|
|
|
lint,
|
|
|
|
'_verify_no_unexpected_files',
|
|
|
|
return_value=[('P003', 'test message')]) as mock_method:
|
2018-03-05 08:10:38 -06:00
|
|
|
lint.full(False, exclude_lint, [])
|
2018-04-02 15:45:00 -05:00
|
|
|
mock_method.assert_called()
|
2018-03-05 08:10:38 -06:00
|
|
|
|
|
|
|
|
|
|
|
@mock.patch.object(lint, '_verify_deckhand_render', return_value=[])
|
|
|
|
@mock.patch.object(lint, '_verify_no_unexpected_files', return_value=[])
|
|
|
|
def test_lint_warns_P001(*args):
|
|
|
|
warn_lint = ['P001']
|
2018-06-25 10:43:43 -07:00
|
|
|
config.set_site_repo('../pegleg/site_yamls/')
|
2018-03-05 08:10:38 -06:00
|
|
|
|
2018-04-02 15:45:00 -05:00
|
|
|
code_1 = 'X001'
|
2018-03-05 08:10:38 -06:00
|
|
|
msg_1 = 'is a secret, but has unexpected storagePolicy: "cleartext"'
|
2018-04-02 15:45:00 -05:00
|
|
|
code_2 = 'X002'
|
2018-03-05 08:10:38 -06:00
|
|
|
msg_2 = 'test msg'
|
2018-04-02 15:45:00 -05:00
|
|
|
msgs = [(code_1, msg_1), (code_2, msg_2)]
|
2018-03-05 08:10:38 -06:00
|
|
|
|
2018-04-02 15:45:00 -05:00
|
|
|
with mock.patch.object(
|
|
|
|
lint, '_verify_file_contents', return_value=msgs) as mock_methed:
|
2018-03-05 08:10:38 -06:00
|
|
|
with pytest.raises(click.ClickException) as expected_exc:
|
|
|
|
lint.full(False, [], warn_lint)
|
|
|
|
assert msg_1 not in expected_exc
|
|
|
|
assert msg_2 in expected_exc
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch.object(lint, '_verify_no_unexpected_files', return_value=[])
|
|
|
|
def test_lint_warns_P002(*args):
|
|
|
|
warn_lint = ['P002']
|
2018-06-25 10:43:43 -07:00
|
|
|
config.set_site_repo('../pegleg/site_yamls/')
|
2018-03-05 08:10:38 -06:00
|
|
|
|
|
|
|
with mock.patch.object(lint, '_verify_deckhand_render') as mock_method:
|
|
|
|
lint.full(False, [], warn_lint)
|
|
|
|
mock_method.assert_called()
|
|
|
|
|
|
|
|
|
2018-06-25 10:43:43 -07:00
|
|
|
@pytest.mark.skip(reason=_SKIP_P003_REASON)
|
2018-03-05 08:10:38 -06:00
|
|
|
@mock.patch.object(lint, '_verify_deckhand_render', return_value=[])
|
|
|
|
def test_lint_warns_P003(*args):
|
|
|
|
warn_lint = ['P003']
|
2018-06-25 10:43:43 -07:00
|
|
|
config.set_site_repo('../pegleg/site_yamls/')
|
2018-03-05 08:10:38 -06:00
|
|
|
|
|
|
|
with mock.patch.object(lint, '_verify_no_unexpected_files') as mock_method:
|
|
|
|
lint.full(False, [], warn_lint)
|
|
|
|
mock_method.assert_called()
|