diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-11 15:38:22 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-12 15:43:37 +0200 |
commit | 534ce6a0a096cede9aff88dd433b4c513003c189 (patch) | |
tree | 2410d35dcbc3db8959ae9b1f12370cba3013ccc8 /test/buildtool/common | |
parent | acd81410b5205cb18a4bba3fea75ff2389f00635 (diff) | |
download | justbuild-534ce6a0a096cede9aff88dd433b4c513003c189.tar.gz |
Remove redundant ArtifactFactory class used in tests only
...and move the related tests to artifact_description.test
Diffstat (limited to 'test/buildtool/common')
-rw-r--r-- | test/buildtool/common/TARGETS | 19 | ||||
-rw-r--r-- | test/buildtool/common/action_description.test.cpp | 12 | ||||
-rw-r--r-- | test/buildtool/common/artifact_description.test.cpp | 60 | ||||
-rw-r--r-- | test/buildtool/common/artifact_factory.test.cpp | 70 |
4 files changed, 64 insertions, 97 deletions
diff --git a/test/buildtool/common/TARGETS b/test/buildtool/common/TARGETS index 986dea0c..c2ce0eac 100644 --- a/test/buildtool/common/TARGETS +++ b/test/buildtool/common/TARGETS @@ -1,24 +1,11 @@ -{ "artifact_factory": - { "type": ["@", "rules", "CC/test", "test"] - , "name": ["artifact_factory"] - , "srcs": ["artifact_factory.test.cpp"] - , "private-deps": - [ ["@", "catch2", "", "catch2"] - , ["", "catch-main"] - , ["@", "json", "", "json"] - , ["@", "src", "src/buildtool/common", "artifact_description"] - , ["@", "src", "src/buildtool/file_system", "object_type"] - ] - , "stage": ["test", "buildtool", "common"] - } -, "artifact_description": +{ "artifact_description": { "type": ["@", "rules", "CC/test", "test"] , "name": ["artifact_description"] , "srcs": ["artifact_description.test.cpp"] , "private-deps": [ ["@", "catch2", "", "catch2"] , ["", "catch-main"] - , ["@", "src", "src/buildtool/common", "artifact_factory"] + , ["@", "json", "", "json"] , ["@", "src", "src/buildtool/common", "artifact_description"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/file_system", "object_type"] @@ -33,7 +20,6 @@ [ ["@", "catch2", "", "catch2"] , ["", "catch-main"] , ["@", "json", "", "json"] - , ["@", "src", "src/buildtool/common", "artifact_factory"] , ["@", "src", "src/buildtool/common", "action_description"] , ["@", "src", "src/buildtool/common", "common"] ] @@ -77,7 +63,6 @@ , "deps": [ "action_description" , "artifact_description" - , "artifact_factory" , "repository_config" , "artifact_object_info" ] diff --git a/test/buildtool/common/action_description.test.cpp b/test/buildtool/common/action_description.test.cpp index 9d82ec9d..c79caeaa 100644 --- a/test/buildtool/common/action_description.test.cpp +++ b/test/buildtool/common/action_description.test.cpp @@ -19,7 +19,6 @@ #include "src/buildtool/common/action.hpp" #include "src/buildtool/common/action_description.hpp" #include "src/buildtool/common/artifact_description.hpp" -#include "src/buildtool/common/artifact_factory.hpp" TEST_CASE("From JSON", "[action_description]") { using path = std::filesystem::path; @@ -30,11 +29,12 @@ TEST_CASE("From JSON", "[action_description]") { {{"path0", ArtifactDescription::CreateTree(path{"input0"})}, {"path1", ArtifactDescription::CreateTree(path{"input1"})}}}; auto const& action = desc.GraphAction(); - auto json = ArtifactFactory::DescribeAction(desc.OutputFiles(), - desc.OutputDirs(), - action.Command(), - desc.Inputs(), - action.Env()); + auto json = + ActionDescription{desc.OutputFiles(), + desc.OutputDirs(), + Action{"unused", action.Command(), action.Env()}, + desc.Inputs()} + .ToJson(); SECTION("Parse full action") { auto description = ActionDescription::FromJson("id", json); diff --git a/test/buildtool/common/artifact_description.test.cpp b/test/buildtool/common/artifact_description.test.cpp index c8fffc46..76e49e34 100644 --- a/test/buildtool/common/artifact_description.test.cpp +++ b/test/buildtool/common/artifact_description.test.cpp @@ -16,9 +16,9 @@ #include <string> #include "catch2/catch_test_macros.hpp" +#include "nlohmann/json.hpp" #include "src/buildtool/common/artifact.hpp" #include "src/buildtool/common/artifact_description.hpp" -#include "src/buildtool/common/artifact_factory.hpp" #include "src/buildtool/file_system/object_type.hpp" [[nodiscard]] auto operator==(Artifact const& lhs, Artifact const& rhs) @@ -66,10 +66,12 @@ TEST_CASE("Action artifact", "[artifact_description]") { } TEST_CASE("From JSON", "[artifact_description]") { - auto local = ArtifactFactory::DescribeLocalArtifact("local", "repo"); + auto local = ArtifactDescription::CreateLocal("local", "repo").ToJson(); auto known = - ArtifactFactory::DescribeKnownArtifact("hash", 0, ObjectType::File); - auto action = ArtifactFactory::DescribeActionArtifact("id", "output"); + ArtifactDescription::CreateKnown( + ArtifactDigest{"hash", 0, /*is_tree=*/false}, ObjectType::File) + .ToJson(); + auto action = ArtifactDescription::CreateAction("id", "output").ToJson(); SECTION("Parse artifacts") { CHECK(ArtifactDescription::FromJson(local)); @@ -144,3 +146,53 @@ TEST_CASE("From JSON", "[artifact_description]") { } } } + +TEST_CASE("Description missing mandatory key/value pair", + "[artifact_description]") { + nlohmann::json const missing_type = {{"data", {{"path", "some/path"}}}}; + CHECK(not ArtifactDescription::FromJson(missing_type)); + nlohmann::json const missing_data = {{"type", "LOCAL"}}; + CHECK(not ArtifactDescription::FromJson(missing_data)); +} + +TEST_CASE("Local artifact description contains incorrect value for \"data\"", + "[artifact_description]") { + nlohmann::json const local_art_missing_path = { + {"type", "LOCAL"}, {"data", nlohmann::json::object()}}; + CHECK(not ArtifactDescription::FromJson(local_art_missing_path)); +} + +TEST_CASE("Known artifact description contains incorrect value for \"data\"", + "[artifact_description]") { + std::string file_type{}; + file_type += ToChar(ObjectType::File); + SECTION("missing \"id\"") { + nlohmann::json const known_art_missing_id = { + {"type", "KNOWN"}, + {"data", {{"size", 15}, {"file_type", file_type}}}}; + CHECK(not ArtifactDescription::FromJson(known_art_missing_id)); + } + SECTION("missing \"size\"") { + nlohmann::json const known_art_missing_size = { + {"type", "KNOWN"}, + {"data", {{"id", "known_input"}, {"file_type", file_type}}}}; + CHECK(not ArtifactDescription::FromJson(known_art_missing_size)); + } + SECTION("missing \"file_type\"") { + nlohmann::json const known_art_missing_file_type = { + {"type", "KNOWN"}, {"data", {{"id", "known_input"}, {"size", 15}}}}; + + CHECK(not ArtifactDescription::FromJson(known_art_missing_file_type)); + } +} + +TEST_CASE("Action artifact description contains incorrect value for \"data\"", + "[artifact_description]") { + nlohmann::json const action_art_missing_id = { + {"type", "ACTION"}, {"data", {{"path", "output/path"}}}}; + CHECK(not ArtifactDescription::FromJson(action_art_missing_id)); + + nlohmann::json const action_art_missing_path = { + {"type", "ACTION"}, {"data", {{"id", "action_id"}}}}; + CHECK(not ArtifactDescription::FromJson(action_art_missing_path)); +} diff --git a/test/buildtool/common/artifact_factory.test.cpp b/test/buildtool/common/artifact_factory.test.cpp deleted file mode 100644 index 222ffd2b..00000000 --- a/test/buildtool/common/artifact_factory.test.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. -// -// 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. - -#include <string> - -#include "catch2/catch_test_macros.hpp" -#include "nlohmann/json.hpp" -#include "src/buildtool/common/artifact_description.hpp" -#include "src/buildtool/file_system/object_type.hpp" - -TEST_CASE("Description missing mandatory key/value pair", - "[artifact_factory]") { - nlohmann::json const missing_type = {{"data", {{"path", "some/path"}}}}; - CHECK(not ArtifactDescription::FromJson(missing_type)); - nlohmann::json const missing_data = {{"type", "LOCAL"}}; - CHECK(not ArtifactDescription::FromJson(missing_data)); -} - -TEST_CASE("Local artifact description contains incorrect value for \"data\"", - "[artifact_factory]") { - nlohmann::json const local_art_missing_path = { - {"type", "LOCAL"}, {"data", nlohmann::json::object()}}; - CHECK(not ArtifactDescription::FromJson(local_art_missing_path)); -} - -TEST_CASE("Known artifact description contains incorrect value for \"data\"", - "[artifact_factory]") { - std::string file_type{}; - file_type += ToChar(ObjectType::File); - SECTION("missing \"id\"") { - nlohmann::json const known_art_missing_id = { - {"type", "KNOWN"}, - {"data", {{"size", 15}, {"file_type", file_type}}}}; - CHECK(not ArtifactDescription::FromJson(known_art_missing_id)); - } - SECTION("missing \"size\"") { - nlohmann::json const known_art_missing_size = { - {"type", "KNOWN"}, - {"data", {{"id", "known_input"}, {"file_type", file_type}}}}; - CHECK(not ArtifactDescription::FromJson(known_art_missing_size)); - } - SECTION("missing \"file_type\"") { - nlohmann::json const known_art_missing_file_type = { - {"type", "KNOWN"}, {"data", {{"id", "known_input"}, {"size", 15}}}}; - - CHECK(not ArtifactDescription::FromJson(known_art_missing_file_type)); - } -} - -TEST_CASE("Action artifact description contains incorrect value for \"data\"", - "[artifact_factory]") { - nlohmann::json const action_art_missing_id = { - {"type", "ACTION"}, {"data", {{"path", "output/path"}}}}; - CHECK(not ArtifactDescription::FromJson(action_art_missing_id)); - - nlohmann::json const action_art_missing_path = { - {"type", "ACTION"}, {"data", {{"id", "action_id"}}}}; - CHECK(not ArtifactDescription::FromJson(action_art_missing_path)); -} |