2023-02-19 16:11:20 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "derivations.hh"
|
|
|
|
|
|
|
|
#include "tests/libstore.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
class DerivationTest : public LibStoreTest
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2023-02-17 23:37:35 +00:00
|
|
|
#define TEST_JSON(NAME, STR, VAL, DRV_NAME, OUTPUT_NAME) \
|
|
|
|
TEST_F(DerivationTest, DerivationOutput_ ## NAME ## _to_json) { \
|
|
|
|
using nlohmann::literals::operator "" _json; \
|
|
|
|
ASSERT_EQ( \
|
|
|
|
STR ## _json, \
|
|
|
|
(DerivationOutput { VAL }).toJSON( \
|
|
|
|
*store, \
|
|
|
|
DRV_NAME, \
|
|
|
|
OUTPUT_NAME)); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
TEST_F(DerivationTest, DerivationOutput_ ## NAME ## _from_json) { \
|
|
|
|
using nlohmann::literals::operator "" _json; \
|
|
|
|
ASSERT_EQ( \
|
|
|
|
DerivationOutput { VAL }, \
|
|
|
|
DerivationOutput::fromJSON( \
|
|
|
|
*store, \
|
|
|
|
DRV_NAME, \
|
|
|
|
OUTPUT_NAME, \
|
|
|
|
STR ## _json)); \
|
2023-02-19 16:11:20 +00:00
|
|
|
}
|
|
|
|
|
2023-02-17 23:37:35 +00:00
|
|
|
TEST_JSON(inputAddressed,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
|
|
|
"path": "/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-drv-name-output-name"
|
|
|
|
})",
|
|
|
|
(DerivationOutput::InputAddressed {
|
|
|
|
.path = store->parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-drv-name-output-name"),
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-02-17 23:37:35 +00:00
|
|
|
TEST_JSON(caFixed,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
|
|
|
"hashAlgo": "r:sha256",
|
|
|
|
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f",
|
|
|
|
"path": "/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-drv-name-output-name"
|
|
|
|
})",
|
|
|
|
(DerivationOutput::CAFixed {
|
2023-02-28 17:46:00 +00:00
|
|
|
.ca = FixedOutputInfo {
|
|
|
|
.hash = {
|
|
|
|
.method = FileIngestionMethod::Recursive,
|
|
|
|
.hash = Hash::parseAnyPrefixed("sha256-iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="),
|
|
|
|
},
|
|
|
|
.references = {},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-04-17 14:16:57 +00:00
|
|
|
TEST_JSON(caFixedText,
|
2023-02-28 17:46:00 +00:00
|
|
|
R"({
|
|
|
|
"hashAlgo": "text:sha256",
|
|
|
|
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f",
|
|
|
|
"path": "/nix/store/6s1zwabh956jvhv4w9xcdb5jiyanyxg1-drv-name-output-name"
|
|
|
|
})",
|
|
|
|
(DerivationOutput::CAFixed {
|
|
|
|
.ca = TextInfo {
|
|
|
|
.hash = {
|
|
|
|
.hash = Hash::parseAnyPrefixed("sha256-iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="),
|
|
|
|
},
|
|
|
|
.references = {},
|
2023-02-19 16:11:20 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-02-17 23:37:35 +00:00
|
|
|
TEST_JSON(caFloating,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
|
|
|
"hashAlgo": "r:sha256"
|
|
|
|
})",
|
|
|
|
(DerivationOutput::CAFloating {
|
|
|
|
.method = FileIngestionMethod::Recursive,
|
|
|
|
.hashType = htSHA256,
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-02-17 23:37:35 +00:00
|
|
|
TEST_JSON(deferred,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({ })",
|
|
|
|
DerivationOutput::Deferred { },
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-02-17 23:37:35 +00:00
|
|
|
TEST_JSON(impure,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
|
|
|
"hashAlgo": "r:sha256",
|
|
|
|
"impure": true
|
|
|
|
})",
|
|
|
|
(DerivationOutput::Impure {
|
|
|
|
.method = FileIngestionMethod::Recursive,
|
|
|
|
.hashType = htSHA256,
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-02-17 23:37:35 +00:00
|
|
|
#undef TEST_JSON
|
|
|
|
|
|
|
|
#define TEST_JSON(NAME, STR, VAL, DRV_NAME) \
|
|
|
|
TEST_F(DerivationTest, Derivation_ ## NAME ## _to_json) { \
|
|
|
|
using nlohmann::literals::operator "" _json; \
|
|
|
|
ASSERT_EQ( \
|
|
|
|
STR ## _json, \
|
|
|
|
(Derivation { VAL }).toJSON(*store)); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
TEST_F(DerivationTest, Derivation_ ## NAME ## _from_json) { \
|
|
|
|
using nlohmann::literals::operator "" _json; \
|
|
|
|
ASSERT_EQ( \
|
|
|
|
Derivation { VAL }, \
|
|
|
|
Derivation::fromJSON( \
|
|
|
|
*store, \
|
|
|
|
STR ## _json)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_JSON(simple,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
2023-03-30 15:06:52 +00:00
|
|
|
"name": "my-derivation",
|
2023-02-19 16:11:20 +00:00
|
|
|
"inputSrcs": [
|
|
|
|
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
|
|
|
|
],
|
|
|
|
"inputDrvs": {
|
|
|
|
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv": [
|
|
|
|
"cat",
|
|
|
|
"dog"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"system": "wasm-sel4",
|
|
|
|
"builder": "foo",
|
|
|
|
"args": [
|
|
|
|
"bar",
|
|
|
|
"baz"
|
|
|
|
],
|
2023-02-20 22:32:19 +00:00
|
|
|
"env": {
|
|
|
|
"BIG_BAD": "WOLF"
|
|
|
|
},
|
2023-02-19 16:11:20 +00:00
|
|
|
"outputs": {}
|
|
|
|
})",
|
|
|
|
({
|
|
|
|
Derivation drv;
|
2023-03-30 15:06:52 +00:00
|
|
|
drv.name = "my-derivation";
|
2023-02-19 16:11:20 +00:00
|
|
|
drv.inputSrcs = {
|
|
|
|
store->parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"),
|
|
|
|
};
|
|
|
|
drv.inputDrvs = {
|
|
|
|
{
|
|
|
|
store->parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv"),
|
|
|
|
{
|
|
|
|
"cat",
|
|
|
|
"dog",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
drv.platform = "wasm-sel4";
|
|
|
|
drv.builder = "foo";
|
|
|
|
drv.args = {
|
|
|
|
"bar",
|
|
|
|
"baz",
|
|
|
|
};
|
2023-02-20 22:32:19 +00:00
|
|
|
drv.env = {
|
|
|
|
{
|
|
|
|
"BIG_BAD",
|
|
|
|
"WOLF",
|
|
|
|
},
|
|
|
|
};
|
2023-02-19 16:11:20 +00:00
|
|
|
drv;
|
2023-02-17 23:37:35 +00:00
|
|
|
}),
|
|
|
|
"drv-name")
|
2023-02-19 16:11:20 +00:00
|
|
|
|
|
|
|
#undef TEST_JSON
|
|
|
|
|
|
|
|
}
|