aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/libstore/serve-protocol.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-04 04:35:39 +0100
committereldritch horrors <pennae@lix.systems>2024-03-04 04:37:05 +0100
commite12e9f2452681a3036884e9e778154b35246d39e (patch)
tree57aaea8bf74c53e28fba9598cea034e9b08ce9f5 /tests/unit/libstore/serve-protocol.cc
parentaeb803de9ad3cd449f7dc85588430ed5b21503eb (diff)
Merge pull request #9137 from obsidiansystems/serve-protocol
Introduce separate Serve protocol serialisers (cherry picked from commit d070d8b7460f412a657745698dba291c66792402) Change-Id: Ibcc8639e8997bcd07f7a5318330a147bcadc411b
Diffstat (limited to 'tests/unit/libstore/serve-protocol.cc')
-rw-r--r--tests/unit/libstore/serve-protocol.cc152
1 files changed, 152 insertions, 0 deletions
diff --git a/tests/unit/libstore/serve-protocol.cc b/tests/unit/libstore/serve-protocol.cc
new file mode 100644
index 000000000..dd7d83e0a
--- /dev/null
+++ b/tests/unit/libstore/serve-protocol.cc
@@ -0,0 +1,152 @@
+#include <regex>
+
+#include <nlohmann/json.hpp>
+#include <gtest/gtest.h>
+
+#include "serve-protocol.hh"
+#include "serve-protocol-impl.hh"
+#include "build-result.hh"
+#include "protocol.hh"
+#include "characterization.hh"
+
+namespace nix {
+
+const char commonProtoDir[] = "serve-protocol";
+
+using ServeProtoTest = ProtoTest<ServeProto, commonProtoDir>;
+
+CHARACTERIZATION_TEST(
+ ServeProtoTest,
+ string,
+ "string",
+ (std::tuple<std::string, std::string, std::string, std::string, std::string> {
+ "",
+ "hi",
+ "white rabbit",
+ "大白兔",
+ "oh no \0\0\0 what was that!",
+ }))
+
+CHARACTERIZATION_TEST(
+ ServeProtoTest,
+ storePath,
+ "store-path",
+ (std::tuple<StorePath, StorePath> {
+ StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
+ StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo-bar" },
+ }))
+
+CHARACTERIZATION_TEST(
+ ServeProtoTest,
+ contentAddress,
+ "content-address",
+ (std::tuple<ContentAddress, ContentAddress, ContentAddress> {
+ ContentAddress {
+ .method = TextIngestionMethod {},
+ .hash = hashString(HashType::htSHA256, "Derive(...)"),
+ },
+ ContentAddress {
+ .method = FileIngestionMethod::Flat,
+ .hash = hashString(HashType::htSHA1, "blob blob..."),
+ },
+ ContentAddress {
+ .method = FileIngestionMethod::Recursive,
+ .hash = hashString(HashType::htSHA256, "(...)"),
+ },
+ }))
+
+CHARACTERIZATION_TEST(
+ ServeProtoTest,
+ drvOutput,
+ "drv-output",
+ (std::tuple<DrvOutput, DrvOutput> {
+ {
+ .drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
+ .outputName = "baz",
+ },
+ DrvOutput {
+ .drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
+ .outputName = "quux",
+ },
+ }))
+
+CHARACTERIZATION_TEST(
+ ServeProtoTest,
+ realisation,
+ "realisation",
+ (std::tuple<Realisation, Realisation> {
+ Realisation {
+ .id = DrvOutput {
+ .drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
+ .outputName = "baz",
+ },
+ .outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
+ .signatures = { "asdf", "qwer" },
+ },
+ Realisation {
+ .id = {
+ .drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
+ .outputName = "baz",
+ },
+ .outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
+ .signatures = { "asdf", "qwer" },
+ .dependentRealisations = {
+ {
+ DrvOutput {
+ .drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
+ .outputName = "quux",
+ },
+ StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
+ },
+ },
+ },
+ }))
+
+CHARACTERIZATION_TEST(
+ ServeProtoTest,
+ vector,
+ "vector",
+ (std::tuple<std::vector<std::string>, std::vector<std::string>, std::vector<std::string>, std::vector<std::vector<std::string>>> {
+ { },
+ { "" },
+ { "", "foo", "bar" },
+ { {}, { "" }, { "", "1", "2" } },
+ }))
+
+CHARACTERIZATION_TEST(
+ ServeProtoTest,
+ set,
+ "set",
+ (std::tuple<std::set<std::string>, std::set<std::string>, std::set<std::string>, std::set<std::set<std::string>>> {
+ { },
+ { "" },
+ { "", "foo", "bar" },
+ { {}, { "" }, { "", "1", "2" } },
+ }))
+
+CHARACTERIZATION_TEST(
+ ServeProtoTest,
+ optionalStorePath,
+ "optional-store-path",
+ (std::tuple<std::optional<StorePath>, std::optional<StorePath>> {
+ std::nullopt,
+ std::optional {
+ StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo-bar" },
+ },
+ }))
+
+CHARACTERIZATION_TEST(
+ ServeProtoTest,
+ optionalContentAddress,
+ "optional-content-address",
+ (std::tuple<std::optional<ContentAddress>, std::optional<ContentAddress>> {
+ std::nullopt,
+ std::optional {
+ ContentAddress {
+ .method = FileIngestionMethod::Flat,
+ .hash = hashString(HashType::htSHA1, "blob blob..."),
+ },
+ },
+ }))
+
+}