2024-03-04 03:35:39 +00:00
|
|
|
#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 {
|
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
const char serveProtoDir[] = "serve-protocol";
|
2024-03-04 03:35:39 +00:00
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
struct ServeProtoTest : VersionedProtoTest<ServeProto, serveProtoDir>
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* For serializers that don't care about the minimum version, we
|
|
|
|
* used the oldest one: 1.0.
|
|
|
|
*/
|
|
|
|
ServeProto::Version defaultVersion = 1 << 8 | 0;
|
|
|
|
};
|
2024-03-04 03:35:39 +00:00
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2024-03-04 03:35:39 +00:00
|
|
|
ServeProtoTest,
|
|
|
|
string,
|
|
|
|
"string",
|
2023-10-20 13:34:26 +00:00
|
|
|
defaultVersion,
|
2024-03-04 03:35:39 +00:00
|
|
|
(std::tuple<std::string, std::string, std::string, std::string, std::string> {
|
|
|
|
"",
|
|
|
|
"hi",
|
|
|
|
"white rabbit",
|
|
|
|
"大白兔",
|
|
|
|
"oh no \0\0\0 what was that!",
|
|
|
|
}))
|
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2024-03-04 03:35:39 +00:00
|
|
|
ServeProtoTest,
|
|
|
|
storePath,
|
|
|
|
"store-path",
|
2023-10-20 13:34:26 +00:00
|
|
|
defaultVersion,
|
2024-03-04 03:35:39 +00:00
|
|
|
(std::tuple<StorePath, StorePath> {
|
|
|
|
StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
|
|
|
StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo-bar" },
|
|
|
|
}))
|
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2024-03-04 03:35:39 +00:00
|
|
|
ServeProtoTest,
|
|
|
|
contentAddress,
|
|
|
|
"content-address",
|
2023-10-20 13:34:26 +00:00
|
|
|
defaultVersion,
|
2024-03-04 03:35:39 +00:00
|
|
|
(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, "(...)"),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2024-03-04 03:35:39 +00:00
|
|
|
ServeProtoTest,
|
|
|
|
drvOutput,
|
|
|
|
"drv-output",
|
2023-10-20 13:34:26 +00:00
|
|
|
defaultVersion,
|
2024-03-04 03:35:39 +00:00
|
|
|
(std::tuple<DrvOutput, DrvOutput> {
|
|
|
|
{
|
|
|
|
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
|
|
|
.outputName = "baz",
|
|
|
|
},
|
|
|
|
DrvOutput {
|
|
|
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
|
|
|
.outputName = "quux",
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2024-03-04 03:35:39 +00:00
|
|
|
ServeProtoTest,
|
|
|
|
realisation,
|
|
|
|
"realisation",
|
2023-10-20 13:34:26 +00:00
|
|
|
defaultVersion,
|
2024-03-04 03:35:39 +00:00
|
|
|
(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" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2024-03-04 03:35:39 +00:00
|
|
|
ServeProtoTest,
|
|
|
|
vector,
|
|
|
|
"vector",
|
2023-10-20 13:34:26 +00:00
|
|
|
defaultVersion,
|
2024-03-04 03:35:39 +00:00
|
|
|
(std::tuple<std::vector<std::string>, std::vector<std::string>, std::vector<std::string>, std::vector<std::vector<std::string>>> {
|
|
|
|
{ },
|
|
|
|
{ "" },
|
|
|
|
{ "", "foo", "bar" },
|
|
|
|
{ {}, { "" }, { "", "1", "2" } },
|
|
|
|
}))
|
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2024-03-04 03:35:39 +00:00
|
|
|
ServeProtoTest,
|
|
|
|
set,
|
|
|
|
"set",
|
2023-10-20 13:34:26 +00:00
|
|
|
defaultVersion,
|
2024-03-04 03:35:39 +00:00
|
|
|
(std::tuple<std::set<std::string>, std::set<std::string>, std::set<std::string>, std::set<std::set<std::string>>> {
|
|
|
|
{ },
|
|
|
|
{ "" },
|
|
|
|
{ "", "foo", "bar" },
|
|
|
|
{ {}, { "" }, { "", "1", "2" } },
|
|
|
|
}))
|
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2024-03-04 03:35:39 +00:00
|
|
|
ServeProtoTest,
|
|
|
|
optionalStorePath,
|
|
|
|
"optional-store-path",
|
2023-10-20 13:34:26 +00:00
|
|
|
defaultVersion,
|
2024-03-04 03:35:39 +00:00
|
|
|
(std::tuple<std::optional<StorePath>, std::optional<StorePath>> {
|
|
|
|
std::nullopt,
|
|
|
|
std::optional {
|
|
|
|
StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo-bar" },
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2023-10-20 13:34:26 +00:00
|
|
|
VERSIONED_CHARACTERIZATION_TEST(
|
2024-03-04 03:35:39 +00:00
|
|
|
ServeProtoTest,
|
|
|
|
optionalContentAddress,
|
|
|
|
"optional-content-address",
|
2023-10-20 13:34:26 +00:00
|
|
|
defaultVersion,
|
2024-03-04 03:35:39 +00:00
|
|
|
(std::tuple<std::optional<ContentAddress>, std::optional<ContentAddress>> {
|
|
|
|
std::nullopt,
|
|
|
|
std::optional {
|
|
|
|
ContentAddress {
|
|
|
|
.method = FileIngestionMethod::Flat,
|
|
|
|
.hash = hashString(HashType::htSHA1, "blob blob..."),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
}
|