|
| 1 | +""" |
| 2 | +Copyright (C) 2022 Red Hat, Inc. (https://github.com/Commonjava/charon) |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +""" |
| 16 | +import os |
| 17 | + |
| 18 | +from moto import mock_aws |
| 19 | + |
| 20 | +from charon.pkgs.npm import handle_npm_uploading |
| 21 | +from charon.constants import DEFAULT_REGISTRY |
| 22 | +from tests.base import PackageBaseTest |
| 23 | +from tests.commons import TEST_BUCKET |
| 24 | +from tests.constants import INPUTS |
| 25 | +import logging |
| 26 | + |
| 27 | +logger = logging.getLogger(f"charon.tests.{__name__}") |
| 28 | + |
| 29 | +CODE_FRAME_FILES_REDHAT = [ |
| 30 | + "@redhat/code-frame/7.14.5/package.json", |
| 31 | + "@redhat/code-frame/-/code-frame-7.14.5-multi-pkgs.tgz" |
| 32 | +] |
| 33 | + |
| 34 | +CODE_FRAME_META_REDHAT = "@redhat/code-frame/package.json" |
| 35 | + |
| 36 | +CODE_FRAME_FILES_BABEL = [ |
| 37 | + "@babel/code-frame/7.14.5/package.json", |
| 38 | + "@babel/code-frame/-/code-frame-7.14.5-no-root-pkg.tgz" |
| 39 | +] |
| 40 | + |
| 41 | +CODE_FRAME_META_BABEL = "@babel/code-frame/package.json" |
| 42 | + |
| 43 | + |
| 44 | +@mock_aws |
| 45 | +class NPMUploadTest(PackageBaseTest): |
| 46 | + |
| 47 | + def test_npm_uploads_multi_pkgjson_with_root(self): |
| 48 | + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5-multi-pkgs.tgz") |
| 49 | + product_7_14_5 = "code-frame-7.14.5" |
| 50 | + handle_npm_uploading( |
| 51 | + test_tgz, product_7_14_5, |
| 52 | + buckets=[('', TEST_BUCKET, '', DEFAULT_REGISTRY)], |
| 53 | + dir_=self.tempdir, do_index=False |
| 54 | + ) |
| 55 | + test_bucket = self.mock_s3.Bucket(TEST_BUCKET) |
| 56 | + objs = list(test_bucket.objects.all()) |
| 57 | + actual_files = [obj.key for obj in objs] |
| 58 | + logger.debug("actual_files: %s", actual_files) |
| 59 | + self.assertEqual(5, len(actual_files)) |
| 60 | + |
| 61 | + for f in CODE_FRAME_FILES_REDHAT: |
| 62 | + self.assertIn(f, actual_files) |
| 63 | + self.check_product(f, [product_7_14_5]) |
| 64 | + self.assertIn(CODE_FRAME_META_REDHAT, actual_files) |
| 65 | + |
| 66 | + meta_obj_client = test_bucket.Object(CODE_FRAME_META_REDHAT) |
| 67 | + meta_content_client = str(meta_obj_client.get()["Body"].read(), "utf-8") |
| 68 | + self.assertIn("\"name\": \"@redhat/code-frame\"", meta_content_client) |
| 69 | + self.assertIn("\"description\": \"Generate errors that contain a code frame that point to " |
| 70 | + "source locations.\"", meta_content_client) |
| 71 | + self.assertIn("\"repository\": {\"type\": \"git\", \"url\": " |
| 72 | + "\"https://github.com/babel/babel.git\"", meta_content_client) |
| 73 | + self.assertIn("\"version\": \"7.14.5\"", meta_content_client) |
| 74 | + self.assertIn("\"versions\": {", meta_content_client) |
| 75 | + self.assertIn("\"7.14.5\": {\"name\":", meta_content_client) |
| 76 | + self.assertIn("\"license\": \"MIT\"", meta_content_client) |
| 77 | + self.assertNotIn("\"dist_tags\":", meta_content_client) |
| 78 | + |
| 79 | + def test_npm_uploads_multi_pkgjson_with_no_root(self): |
| 80 | + test_tgz = os.path.join(INPUTS, "code-frame-7.14.5-no-root-pkg.tgz") |
| 81 | + product_7_14_5 = "code-frame-7.14.5" |
| 82 | + handle_npm_uploading( |
| 83 | + test_tgz, product_7_14_5, |
| 84 | + buckets=[('', TEST_BUCKET, '', DEFAULT_REGISTRY)], |
| 85 | + dir_=self.tempdir, do_index=False |
| 86 | + ) |
| 87 | + test_bucket = self.mock_s3.Bucket(TEST_BUCKET) |
| 88 | + objs = list(test_bucket.objects.all()) |
| 89 | + actual_files = [obj.key for obj in objs] |
| 90 | + logger.debug("actual_files: %s", actual_files) |
| 91 | + self.assertEqual(5, len(actual_files)) |
| 92 | + |
| 93 | + for f in CODE_FRAME_FILES_BABEL: |
| 94 | + self.assertIn(f, actual_files) |
| 95 | + self.check_product(f, [product_7_14_5]) |
| 96 | + self.assertIn(CODE_FRAME_META_BABEL, actual_files) |
| 97 | + |
| 98 | + meta_obj_client = test_bucket.Object(CODE_FRAME_META_BABEL) |
| 99 | + meta_content_client = str(meta_obj_client.get()["Body"].read(), "utf-8") |
| 100 | + self.assertIn("\"name\": \"@babel/code-frame\"", meta_content_client) |
| 101 | + self.assertIn("\"description\": \"Generate errors that contain a code frame that point to " |
| 102 | + "source locations.\"", meta_content_client) |
| 103 | + self.assertIn("\"repository\": {\"type\": \"git\", \"url\": " |
| 104 | + "\"https://github.com/babel/babel.git\"", meta_content_client) |
| 105 | + self.assertIn("\"version\": \"7.14.5\"", meta_content_client) |
| 106 | + self.assertIn("\"versions\": {", meta_content_client) |
| 107 | + self.assertIn("\"7.14.5\": {\"name\":", meta_content_client) |
| 108 | + self.assertIn("\"license\": \"MIT\"", meta_content_client) |
| 109 | + self.assertNotIn("\"dist_tags\":", meta_content_client) |
0 commit comments