blob: dc71d91c276e9e87dd67cd05a4a6a233692b1b07 [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright 2020 Whitestack, LLC
# *************************************************************
#
# This file is part of OSM common repository.
# All Rights Reserved to Whitestack, LLC
#
# 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.
#
# For those usages not covered by the Apache License, Version 2.0 please
# contact: agarcia@whitestack.com
##
from osm_common.sol004_package import SOL004Package, SOL004PackageException
import unittest
class SOL004ValidatorTest(unittest.TestCase):
def test_get_package_file_hash_algorithm_from_manifest_with_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
)
algorithm = package.get_package_file_hash_algorithm_from_manifest(
"Scripts/charms/simple/src/charm.py"
)
self.assertEqual(algorithm, "SHA-256")
def test_get_package_file_hash_algorithm_from_manifest_without_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
)
algorithm = package.get_package_file_hash_algorithm_from_manifest(
"Scripts/charms/simple/src/charm.py"
)
self.assertEqual(algorithm, "SHA-256")
def test_get_package_file_hash_algorithm_from_manifest_on_non_existent_file(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
)
with self.assertRaises(SOL004PackageException):
package.get_package_file_hash_algorithm_from_manifest("Non/Existing/file")
def test_get_package_file_hash_digest_from_manifest_with_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
)
digest = package.get_package_file_hash_digest_from_manifest(
"Scripts/charms/simple/src/charm.py"
)
self.assertEqual(
digest, "ea72f897a966e6174ed9164fabc3c500df5a2f712eb6b22ab2408afb07d04d14"
)
def test_get_package_file_hash_digest_from_manifest_without_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
)
digest = package.get_package_file_hash_digest_from_manifest(
"Scripts/charms/simple/src/charm.py"
)
self.assertEqual(
digest, "ea72f897a966e6174ed9164fabc3c500df5a2f712eb6b22ab2408afb07d04d14"
)
def test_get_package_file_hash_digest_from_manifest_on_non_existent_file(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
)
with self.assertRaises(SOL004PackageException):
package.get_package_file_hash_digest_from_manifest("Non/Existing/file")
def test_get_package_file_hash_digest_from_manifest_on_non_existing_hash_entry(
self,
):
package = SOL004Package("osm_common/tests/packages/invalid_package_vnf")
with self.assertRaises(SOL004PackageException):
package.get_package_file_hash_digest_from_manifest(
"Scripts/charms/simple/hooks/upgrade-charm"
)
def test_validate_package_file_hash_with_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
)
package.validate_package_file_hash("Scripts/charms/simple/src/charm.py")
def test_validate_package_file_hash_without_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
)
package.validate_package_file_hash("Scripts/charms/simple/src/charm.py")
def test_validate_package_file_hash_on_non_existing_file(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
)
with self.assertRaises(SOL004PackageException):
package.validate_package_file_hash("Non/Existing/file")
def test_validate_package_file_hash_on_wrong_manifest_hash(self):
package = SOL004Package("osm_common/tests/packages/invalid_package_vnf")
with self.assertRaises(SOL004PackageException):
package.validate_package_file_hash("Scripts/charms/simple/hooks/start")
def test_validate_package_file_hash_on_unsupported_hash_algorithm(self):
package = SOL004Package("osm_common/tests/packages/invalid_package_vnf")
with self.assertRaises(SOL004PackageException):
package.validate_package_file_hash("Scripts/charms/simple/src/charm.py")
def test_validate_package_hashes_with_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
)
package.validate_package_hashes()
def test_validate_package_hashes_without_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
)
package.validate_package_hashes()
def test_validate_package_hashes_on_invalid_package(self):
package = SOL004Package("osm_common/tests/packages/invalid_package_vnf")
with self.assertRaises(SOL004PackageException):
package.validate_package_hashes()
def test_get_descriptor_location_with_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
)
descriptor_path = package.get_descriptor_location()
self.assertEqual(descriptor_path, "Definitions/native_charm_vnfd.yaml")
def test_get_descriptor_location_without_metadata_dir(self):
package = SOL004Package(
"osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
)
descriptor_path = package.get_descriptor_location()
self.assertEqual(descriptor_path, "native_charm_vnfd.yaml")