mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
Clean up DerivationOptions unit tests
We now test equality on whole strucks much more often, which avoids forgetting to test for specific fields.
This commit is contained in:
parent
341c42f321
commit
9daef9cca2
1 changed files with 252 additions and 282 deletions
|
|
@ -32,6 +32,33 @@ public:
|
||||||
* to worry about race conditions if the tests run concurrently.
|
* to worry about race conditions if the tests run concurrently.
|
||||||
*/
|
*/
|
||||||
ExperimentalFeatureSettings mockXpSettings;
|
ExperimentalFeatureSettings mockXpSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to test getRequiredSystemFeatures for a given derivation file
|
||||||
|
*/
|
||||||
|
void testRequiredSystemFeatures(const std::string & fileName, const StringSet & expectedFeatures)
|
||||||
|
{
|
||||||
|
this->readTest(fileName, [&](auto encoded) {
|
||||||
|
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
||||||
|
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
||||||
|
EXPECT_EQ(options.getRequiredSystemFeatures(got), expectedFeatures);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to test DerivationOptions parsing and comparison
|
||||||
|
*/
|
||||||
|
void testDerivationOptions(
|
||||||
|
const std::string & fileName, const DerivationOptions & expected, const StringSet & expectedSystemFeatures)
|
||||||
|
{
|
||||||
|
this->readTest(fileName, [&](auto encoded) {
|
||||||
|
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
||||||
|
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
||||||
|
|
||||||
|
EXPECT_EQ(options, expected);
|
||||||
|
EXPECT_EQ(options.getRequiredSystemFeatures(got), expectedSystemFeatures);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CaDerivationAdvancedAttrsTest : public DerivationAdvancedAttrsTest
|
class CaDerivationAdvancedAttrsTest : public DerivationAdvancedAttrsTest
|
||||||
|
|
@ -100,33 +127,35 @@ TEST_ATERM_JSON(advancedAttributes_structuredAttrs_defaults, "advanced-attribute
|
||||||
|
|
||||||
using ExportReferencesMap = decltype(DerivationOptions::exportReferencesGraph);
|
using ExportReferencesMap = decltype(DerivationOptions::exportReferencesGraph);
|
||||||
|
|
||||||
|
static const DerivationOptions advancedAttributes_defaults = {
|
||||||
|
.outputChecks =
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.ignoreSelfRefs = true,
|
||||||
|
},
|
||||||
|
.unsafeDiscardReferences = {},
|
||||||
|
.passAsFile = {},
|
||||||
|
.exportReferencesGraph = {},
|
||||||
|
.additionalSandboxProfile = "",
|
||||||
|
.noChroot = false,
|
||||||
|
.impureHostDeps = {},
|
||||||
|
.impureEnvVars = {},
|
||||||
|
.allowLocalNetworking = false,
|
||||||
|
.requiredSystemFeatures = {},
|
||||||
|
.preferLocalBuild = false,
|
||||||
|
.allowSubstitutes = true,
|
||||||
|
};
|
||||||
|
|
||||||
TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_defaults)
|
TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_defaults)
|
||||||
{
|
{
|
||||||
this->readTest("advanced-attributes-defaults.drv", [&](auto encoded) {
|
this->readTest("advanced-attributes-defaults.drv", [&](auto encoded) {
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
||||||
|
|
||||||
EXPECT_TRUE(!got.structuredAttrs);
|
EXPECT_TRUE(!got.structuredAttrs);
|
||||||
|
|
||||||
EXPECT_EQ(options.additionalSandboxProfile, "");
|
EXPECT_EQ(options, advancedAttributes_defaults);
|
||||||
EXPECT_EQ(options.noChroot, false);
|
|
||||||
EXPECT_EQ(options.impureHostDeps, StringSet{});
|
|
||||||
EXPECT_EQ(options.impureEnvVars, StringSet{});
|
|
||||||
EXPECT_EQ(options.allowLocalNetworking, false);
|
|
||||||
EXPECT_EQ(options.exportReferencesGraph, ExportReferencesMap{});
|
|
||||||
{
|
|
||||||
auto * checksForAllOutputs_ = std::get_if<0>(&options.outputChecks);
|
|
||||||
ASSERT_TRUE(checksForAllOutputs_ != nullptr);
|
|
||||||
auto & checksForAllOutputs = *checksForAllOutputs_;
|
|
||||||
|
|
||||||
EXPECT_EQ(checksForAllOutputs.allowedReferences, std::nullopt);
|
|
||||||
EXPECT_EQ(checksForAllOutputs.allowedRequisites, std::nullopt);
|
|
||||||
EXPECT_EQ(checksForAllOutputs.disallowedReferences, StringSet{});
|
|
||||||
EXPECT_EQ(checksForAllOutputs.disallowedRequisites, StringSet{});
|
|
||||||
}
|
|
||||||
EXPECT_EQ(options.canBuildLocally(*this->store, got), false);
|
EXPECT_EQ(options.canBuildLocally(*this->store, got), false);
|
||||||
EXPECT_EQ(options.willBuildLocally(*this->store, got), false);
|
EXPECT_EQ(options.willBuildLocally(*this->store, got), false);
|
||||||
EXPECT_EQ(options.substitutesAllowed(), true);
|
EXPECT_EQ(options.substitutesAllowed(), true);
|
||||||
|
|
@ -136,152 +165,124 @@ TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_defaults)
|
||||||
|
|
||||||
TEST_F(DerivationAdvancedAttrsTest, advancedAttributes_defaults)
|
TEST_F(DerivationAdvancedAttrsTest, advancedAttributes_defaults)
|
||||||
{
|
{
|
||||||
this->readTest("advanced-attributes-defaults.drv", [&](auto encoded) {
|
testRequiredSystemFeatures("advanced-attributes-defaults.drv", {});
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
|
||||||
|
|
||||||
EXPECT_EQ(options.getRequiredSystemFeatures(got), StringSet{});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CaDerivationAdvancedAttrsTest, advancedAttributes_defaults)
|
TEST_F(CaDerivationAdvancedAttrsTest, advancedAttributes_defaults)
|
||||||
{
|
{
|
||||||
this->readTest("advanced-attributes-defaults.drv", [&](auto encoded) {
|
testRequiredSystemFeatures("advanced-attributes-defaults.drv", {"ca-derivations"});
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
|
||||||
|
|
||||||
EXPECT_EQ(options.getRequiredSystemFeatures(got), StringSet{"ca-derivations"});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes)
|
TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes)
|
||||||
{
|
{
|
||||||
|
DerivationOptions expected = {
|
||||||
|
.outputChecks =
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.ignoreSelfRefs = true,
|
||||||
|
},
|
||||||
|
.unsafeDiscardReferences = {},
|
||||||
|
.passAsFile = {},
|
||||||
|
.additionalSandboxProfile = "sandcastle",
|
||||||
|
.noChroot = true,
|
||||||
|
.impureHostDeps = {"/usr/bin/ditto"},
|
||||||
|
.impureEnvVars = {"UNICORN"},
|
||||||
|
.allowLocalNetworking = true,
|
||||||
|
.requiredSystemFeatures = {"rainbow", "uid-range"},
|
||||||
|
.preferLocalBuild = true,
|
||||||
|
.allowSubstitutes = false,
|
||||||
|
};
|
||||||
|
|
||||||
this->readTest("advanced-attributes.drv", [&](auto encoded) {
|
this->readTest("advanced-attributes.drv", [&](auto encoded) {
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
||||||
|
|
||||||
EXPECT_TRUE(!got.structuredAttrs);
|
EXPECT_TRUE(!got.structuredAttrs);
|
||||||
|
|
||||||
EXPECT_EQ(options.additionalSandboxProfile, "sandcastle");
|
// Reset fields that vary between test cases to enable whole-object comparison
|
||||||
EXPECT_EQ(options.noChroot, true);
|
options.outputChecks = DerivationOptions::OutputChecks{.ignoreSelfRefs = true};
|
||||||
EXPECT_EQ(options.impureHostDeps, StringSet{"/usr/bin/ditto"});
|
options.exportReferencesGraph = {};
|
||||||
EXPECT_EQ(options.impureEnvVars, StringSet{"UNICORN"});
|
|
||||||
EXPECT_EQ(options.allowLocalNetworking, true);
|
EXPECT_EQ(options, expected);
|
||||||
EXPECT_EQ(options.canBuildLocally(*this->store, got), false);
|
|
||||||
EXPECT_EQ(options.willBuildLocally(*this->store, got), false);
|
|
||||||
EXPECT_EQ(options.substitutesAllowed(), false);
|
EXPECT_EQ(options.substitutesAllowed(), false);
|
||||||
EXPECT_EQ(options.useUidRange(got), true);
|
EXPECT_EQ(options.useUidRange(got), true);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(DerivationAdvancedAttrsTest, advancedAttributes)
|
DerivationOptions advancedAttributes_ia = {
|
||||||
|
.outputChecks =
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.ignoreSelfRefs = true,
|
||||||
|
.allowedReferences = StringSet{"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"},
|
||||||
|
.disallowedReferences = StringSet{"/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar"},
|
||||||
|
.allowedRequisites = StringSet{"/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev"},
|
||||||
|
.disallowedRequisites = StringSet{"/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"},
|
||||||
|
},
|
||||||
|
.unsafeDiscardReferences = {},
|
||||||
|
.passAsFile = {},
|
||||||
|
.exportReferencesGraph{
|
||||||
|
{"refs1", {"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"}},
|
||||||
|
{"refs2", {"/nix/store/vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv"}},
|
||||||
|
},
|
||||||
|
.additionalSandboxProfile = "sandcastle",
|
||||||
|
.noChroot = true,
|
||||||
|
.impureHostDeps = {"/usr/bin/ditto"},
|
||||||
|
.impureEnvVars = {"UNICORN"},
|
||||||
|
.allowLocalNetworking = true,
|
||||||
|
.requiredSystemFeatures = {"rainbow", "uid-range"},
|
||||||
|
.preferLocalBuild = true,
|
||||||
|
.allowSubstitutes = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(DerivationAdvancedAttrsTest, advancedAttributes_ia)
|
||||||
{
|
{
|
||||||
this->readTest("advanced-attributes.drv", [&](auto encoded) {
|
testDerivationOptions("advanced-attributes.drv", advancedAttributes_ia, {"rainbow", "uid-range"});
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
};
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
DerivationOptions advancedAttributes_ca = {
|
||||||
|
.outputChecks =
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
DerivationOptions::OutputChecks{
|
||||||
|
.ignoreSelfRefs = true,
|
||||||
EXPECT_EQ(
|
.allowedReferences = StringSet{"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"},
|
||||||
options.exportReferencesGraph,
|
.disallowedReferences = StringSet{"/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g"},
|
||||||
(ExportReferencesMap{
|
.allowedRequisites = StringSet{"/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z"},
|
||||||
{
|
.disallowedRequisites = StringSet{"/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8"},
|
||||||
"refs1",
|
},
|
||||||
{
|
.unsafeDiscardReferences = {},
|
||||||
"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo",
|
.passAsFile = {},
|
||||||
},
|
.exportReferencesGraph{
|
||||||
},
|
{"refs1", {"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"}},
|
||||||
{
|
{"refs2", {"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"}},
|
||||||
"refs2",
|
},
|
||||||
{
|
.additionalSandboxProfile = "sandcastle",
|
||||||
"/nix/store/vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv",
|
.noChroot = true,
|
||||||
},
|
.impureHostDeps = {"/usr/bin/ditto"},
|
||||||
},
|
.impureEnvVars = {"UNICORN"},
|
||||||
}));
|
.allowLocalNetworking = true,
|
||||||
|
.requiredSystemFeatures = {"rainbow", "uid-range"},
|
||||||
{
|
.preferLocalBuild = true,
|
||||||
auto * checksForAllOutputs_ = std::get_if<0>(&options.outputChecks);
|
.allowSubstitutes = false,
|
||||||
ASSERT_TRUE(checksForAllOutputs_ != nullptr);
|
|
||||||
auto & checksForAllOutputs = *checksForAllOutputs_;
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
checksForAllOutputs.allowedReferences, StringSet{"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"});
|
|
||||||
EXPECT_EQ(
|
|
||||||
checksForAllOutputs.allowedRequisites,
|
|
||||||
StringSet{"/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev"});
|
|
||||||
EXPECT_EQ(
|
|
||||||
checksForAllOutputs.disallowedReferences, StringSet{"/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar"});
|
|
||||||
EXPECT_EQ(
|
|
||||||
checksForAllOutputs.disallowedRequisites,
|
|
||||||
StringSet{"/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"});
|
|
||||||
}
|
|
||||||
|
|
||||||
StringSet systemFeatures{"rainbow", "uid-range"};
|
|
||||||
|
|
||||||
EXPECT_EQ(options.getRequiredSystemFeatures(got), systemFeatures);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CaDerivationAdvancedAttrsTest, advancedAttributes)
|
TEST_F(CaDerivationAdvancedAttrsTest, advancedAttributes)
|
||||||
{
|
{
|
||||||
this->readTest("advanced-attributes.drv", [&](auto encoded) {
|
testDerivationOptions("advanced-attributes.drv", advancedAttributes_ca, {"rainbow", "uid-range", "ca-derivations"});
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
};
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
DerivationOptions advancedAttributes_structuredAttrs_defaults = {
|
||||||
|
.outputChecks = std::map<std::string, DerivationOptions::OutputChecks>{},
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
.unsafeDiscardReferences = {},
|
||||||
|
.passAsFile = {},
|
||||||
EXPECT_EQ(
|
.exportReferencesGraph = {},
|
||||||
options.exportReferencesGraph,
|
.additionalSandboxProfile = "",
|
||||||
(ExportReferencesMap{
|
.noChroot = false,
|
||||||
{
|
.impureHostDeps = {},
|
||||||
"refs1",
|
.impureEnvVars = {},
|
||||||
{
|
.allowLocalNetworking = false,
|
||||||
"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9",
|
.requiredSystemFeatures = {},
|
||||||
},
|
.preferLocalBuild = false,
|
||||||
},
|
.allowSubstitutes = true,
|
||||||
{
|
|
||||||
"refs2",
|
|
||||||
{
|
|
||||||
"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
{
|
|
||||||
auto * checksForAllOutputs_ = std::get_if<0>(&options.outputChecks);
|
|
||||||
ASSERT_TRUE(checksForAllOutputs_ != nullptr);
|
|
||||||
auto & checksForAllOutputs = *checksForAllOutputs_;
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
checksForAllOutputs.allowedReferences,
|
|
||||||
StringSet{"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"});
|
|
||||||
EXPECT_EQ(
|
|
||||||
checksForAllOutputs.allowedRequisites,
|
|
||||||
StringSet{"/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z"});
|
|
||||||
EXPECT_EQ(
|
|
||||||
checksForAllOutputs.disallowedReferences,
|
|
||||||
StringSet{"/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g"});
|
|
||||||
EXPECT_EQ(
|
|
||||||
checksForAllOutputs.disallowedRequisites,
|
|
||||||
StringSet{"/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8"});
|
|
||||||
}
|
|
||||||
|
|
||||||
StringSet systemFeatures{"rainbow", "uid-range"};
|
|
||||||
systemFeatures.insert("ca-derivations");
|
|
||||||
|
|
||||||
EXPECT_EQ(options.getRequiredSystemFeatures(got), systemFeatures);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_structuredAttrs_defaults)
|
TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_structuredAttrs_defaults)
|
||||||
|
|
@ -289,26 +290,11 @@ TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_structuredAttrs_d
|
||||||
this->readTest("advanced-attributes-structured-attrs-defaults.drv", [&](auto encoded) {
|
this->readTest("advanced-attributes-structured-attrs-defaults.drv", [&](auto encoded) {
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
||||||
|
|
||||||
EXPECT_TRUE(got.structuredAttrs);
|
EXPECT_TRUE(got.structuredAttrs);
|
||||||
|
|
||||||
EXPECT_EQ(options.additionalSandboxProfile, "");
|
EXPECT_EQ(options, advancedAttributes_structuredAttrs_defaults);
|
||||||
EXPECT_EQ(options.noChroot, false);
|
|
||||||
EXPECT_EQ(options.impureHostDeps, StringSet{});
|
|
||||||
EXPECT_EQ(options.impureEnvVars, StringSet{});
|
|
||||||
EXPECT_EQ(options.allowLocalNetworking, false);
|
|
||||||
EXPECT_EQ(options.exportReferencesGraph, ExportReferencesMap{});
|
|
||||||
|
|
||||||
{
|
|
||||||
auto * checksPerOutput_ = std::get_if<1>(&options.outputChecks);
|
|
||||||
ASSERT_TRUE(checksPerOutput_ != nullptr);
|
|
||||||
auto & checksPerOutput = *checksPerOutput_;
|
|
||||||
|
|
||||||
EXPECT_EQ(checksPerOutput.size(), 0u);
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_EQ(options.canBuildLocally(*this->store, got), false);
|
EXPECT_EQ(options.canBuildLocally(*this->store, got), false);
|
||||||
EXPECT_EQ(options.willBuildLocally(*this->store, got), false);
|
EXPECT_EQ(options.willBuildLocally(*this->store, got), false);
|
||||||
|
|
@ -319,55 +305,61 @@ TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_structuredAttrs_d
|
||||||
|
|
||||||
TEST_F(DerivationAdvancedAttrsTest, advancedAttributes_structuredAttrs_defaults)
|
TEST_F(DerivationAdvancedAttrsTest, advancedAttributes_structuredAttrs_defaults)
|
||||||
{
|
{
|
||||||
this->readTest("advanced-attributes-structured-attrs-defaults.drv", [&](auto encoded) {
|
testRequiredSystemFeatures("advanced-attributes-structured-attrs-defaults.drv", {});
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
|
||||||
|
|
||||||
EXPECT_EQ(options.getRequiredSystemFeatures(got), StringSet{});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CaDerivationAdvancedAttrsTest, advancedAttributes_structuredAttrs_defaults)
|
TEST_F(CaDerivationAdvancedAttrsTest, advancedAttributes_structuredAttrs_defaults)
|
||||||
{
|
{
|
||||||
this->readTest("advanced-attributes-structured-attrs-defaults.drv", [&](auto encoded) {
|
testRequiredSystemFeatures("advanced-attributes-structured-attrs-defaults.drv", {"ca-derivations"});
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
|
||||||
|
|
||||||
EXPECT_EQ(options.getRequiredSystemFeatures(got), StringSet{"ca-derivations"});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_structuredAttrs)
|
TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_structuredAttrs)
|
||||||
{
|
{
|
||||||
|
DerivationOptions expected = {
|
||||||
|
.outputChecks =
|
||||||
|
std::map<std::string, DerivationOptions::OutputChecks>{
|
||||||
|
{"dev",
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.maxSize = 789,
|
||||||
|
.maxClosureSize = 5909,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
.unsafeDiscardReferences = {},
|
||||||
|
.passAsFile = {},
|
||||||
|
.exportReferencesGraph = {},
|
||||||
|
.additionalSandboxProfile = "sandcastle",
|
||||||
|
.noChroot = true,
|
||||||
|
.impureHostDeps = {"/usr/bin/ditto"},
|
||||||
|
.impureEnvVars = {"UNICORN"},
|
||||||
|
.allowLocalNetworking = true,
|
||||||
|
.requiredSystemFeatures = {"rainbow", "uid-range"},
|
||||||
|
.preferLocalBuild = true,
|
||||||
|
.allowSubstitutes = false,
|
||||||
|
};
|
||||||
|
|
||||||
this->readTest("advanced-attributes-structured-attrs.drv", [&](auto encoded) {
|
this->readTest("advanced-attributes-structured-attrs.drv", [&](auto encoded) {
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
||||||
|
|
||||||
EXPECT_TRUE(got.structuredAttrs);
|
EXPECT_TRUE(got.structuredAttrs);
|
||||||
|
|
||||||
EXPECT_EQ(options.additionalSandboxProfile, "sandcastle");
|
// Reset fields that vary between test cases to enable whole-object comparison
|
||||||
EXPECT_EQ(options.noChroot, true);
|
|
||||||
EXPECT_EQ(options.impureHostDeps, StringSet{"/usr/bin/ditto"});
|
|
||||||
EXPECT_EQ(options.impureEnvVars, StringSet{"UNICORN"});
|
|
||||||
EXPECT_EQ(options.allowLocalNetworking, true);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto output_ = get(std::get<1>(options.outputChecks), "dev");
|
// Delete all keys but "dev" in options.outputChecks
|
||||||
ASSERT_TRUE(output_);
|
auto * outputChecksMapP =
|
||||||
auto & output = *output_;
|
std::get_if<std::map<std::string, DerivationOptions::OutputChecks>>(&options.outputChecks);
|
||||||
|
ASSERT_TRUE(outputChecksMapP);
|
||||||
EXPECT_EQ(output.maxSize, 789);
|
auto & outputChecksMap = *outputChecksMapP;
|
||||||
EXPECT_EQ(output.maxClosureSize, 5909);
|
auto devEntry = outputChecksMap.find("dev");
|
||||||
|
ASSERT_TRUE(devEntry != outputChecksMap.end());
|
||||||
|
auto devChecks = devEntry->second;
|
||||||
|
outputChecksMap.clear();
|
||||||
|
outputChecksMap.emplace("dev", std::move(devChecks));
|
||||||
}
|
}
|
||||||
|
options.exportReferencesGraph = {};
|
||||||
|
|
||||||
|
EXPECT_EQ(options, expected);
|
||||||
|
|
||||||
EXPECT_EQ(options.canBuildLocally(*this->store, got), false);
|
EXPECT_EQ(options.canBuildLocally(*this->store, got), false);
|
||||||
EXPECT_EQ(options.willBuildLocally(*this->store, got), false);
|
EXPECT_EQ(options.willBuildLocally(*this->store, got), false);
|
||||||
|
|
@ -376,112 +368,90 @@ TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_structuredAttrs)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DerivationOptions advancedAttributes_structuredAttrs_ia = {
|
||||||
|
.outputChecks =
|
||||||
|
std::map<std::string, DerivationOptions::OutputChecks>{
|
||||||
|
{"out",
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.allowedReferences = StringSet{"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"},
|
||||||
|
.allowedRequisites = StringSet{"/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev"},
|
||||||
|
}},
|
||||||
|
{"bin",
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.disallowedReferences = StringSet{"/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar"},
|
||||||
|
.disallowedRequisites = StringSet{"/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"},
|
||||||
|
}},
|
||||||
|
{"dev",
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.maxSize = 789,
|
||||||
|
.maxClosureSize = 5909,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
.unsafeDiscardReferences = {},
|
||||||
|
.passAsFile = {},
|
||||||
|
.exportReferencesGraph =
|
||||||
|
{
|
||||||
|
{"refs1", {"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"}},
|
||||||
|
{"refs2", {"/nix/store/vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv"}},
|
||||||
|
},
|
||||||
|
.additionalSandboxProfile = "sandcastle",
|
||||||
|
.noChroot = true,
|
||||||
|
.impureHostDeps = {"/usr/bin/ditto"},
|
||||||
|
.impureEnvVars = {"UNICORN"},
|
||||||
|
.allowLocalNetworking = true,
|
||||||
|
.requiredSystemFeatures = {"rainbow", "uid-range"},
|
||||||
|
.preferLocalBuild = true,
|
||||||
|
.allowSubstitutes = false,
|
||||||
|
};
|
||||||
|
|
||||||
TEST_F(DerivationAdvancedAttrsTest, advancedAttributes_structuredAttrs)
|
TEST_F(DerivationAdvancedAttrsTest, advancedAttributes_structuredAttrs)
|
||||||
{
|
{
|
||||||
this->readTest("advanced-attributes-structured-attrs.drv", [&](auto encoded) {
|
testDerivationOptions(
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
"advanced-attributes-structured-attrs.drv", advancedAttributes_structuredAttrs_ia, {"rainbow", "uid-range"});
|
||||||
|
};
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
options.exportReferencesGraph,
|
|
||||||
(ExportReferencesMap{
|
|
||||||
{
|
|
||||||
"refs1",
|
|
||||||
{
|
|
||||||
"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"refs2",
|
|
||||||
{
|
|
||||||
"/nix/store/vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
DerivationOptions advancedAttributes_structuredAttrs_ca = {
|
||||||
|
.outputChecks =
|
||||||
|
std::map<std::string, DerivationOptions::OutputChecks>{
|
||||||
|
{"out",
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.allowedReferences = StringSet{"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"},
|
||||||
|
.allowedRequisites = StringSet{"/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z"},
|
||||||
|
}},
|
||||||
|
{"bin",
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.disallowedReferences = StringSet{"/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g"},
|
||||||
|
.disallowedRequisites = StringSet{"/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8"},
|
||||||
|
}},
|
||||||
|
{"dev",
|
||||||
|
DerivationOptions::OutputChecks{
|
||||||
|
.maxSize = 789,
|
||||||
|
.maxClosureSize = 5909,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
.unsafeDiscardReferences = {},
|
||||||
|
.passAsFile = {},
|
||||||
|
.exportReferencesGraph =
|
||||||
{
|
{
|
||||||
{
|
{"refs1", {"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"}},
|
||||||
auto output_ = get(std::get<1>(options.outputChecks), "out");
|
{"refs2", {"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"}},
|
||||||
ASSERT_TRUE(output_);
|
},
|
||||||
auto & output = *output_;
|
.additionalSandboxProfile = "sandcastle",
|
||||||
|
.noChroot = true,
|
||||||
EXPECT_EQ(output.allowedReferences, StringSet{"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"});
|
.impureHostDeps = {"/usr/bin/ditto"},
|
||||||
EXPECT_EQ(output.allowedRequisites, StringSet{"/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev"});
|
.impureEnvVars = {"UNICORN"},
|
||||||
}
|
.allowLocalNetworking = true,
|
||||||
|
.requiredSystemFeatures = {"rainbow", "uid-range"},
|
||||||
{
|
.preferLocalBuild = true,
|
||||||
auto output_ = get(std::get<1>(options.outputChecks), "bin");
|
.allowSubstitutes = false,
|
||||||
ASSERT_TRUE(output_);
|
|
||||||
auto & output = *output_;
|
|
||||||
|
|
||||||
EXPECT_EQ(output.disallowedReferences, StringSet{"/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar"});
|
|
||||||
EXPECT_EQ(
|
|
||||||
output.disallowedRequisites, StringSet{"/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StringSet systemFeatures{"rainbow", "uid-range"};
|
|
||||||
|
|
||||||
EXPECT_EQ(options.getRequiredSystemFeatures(got), systemFeatures);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CaDerivationAdvancedAttrsTest, advancedAttributes_structuredAttrs)
|
TEST_F(CaDerivationAdvancedAttrsTest, advancedAttributes_structuredAttrs)
|
||||||
{
|
{
|
||||||
this->readTest("advanced-attributes-structured-attrs.drv", [&](auto encoded) {
|
testDerivationOptions(
|
||||||
auto got = parseDerivation(*this->store, std::move(encoded), "foo", this->mockXpSettings);
|
"advanced-attributes-structured-attrs.drv",
|
||||||
|
advancedAttributes_structuredAttrs_ca,
|
||||||
auto drvPath = writeDerivation(*this->store, got, NoRepair, true);
|
{"rainbow", "uid-range", "ca-derivations"});
|
||||||
|
|
||||||
DerivationOptions options = DerivationOptions::fromStructuredAttrs(got.env, got.structuredAttrs);
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
options.exportReferencesGraph,
|
|
||||||
(ExportReferencesMap{
|
|
||||||
{
|
|
||||||
"refs1",
|
|
||||||
{
|
|
||||||
"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"refs2",
|
|
||||||
{
|
|
||||||
"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
{
|
|
||||||
{
|
|
||||||
auto output_ = get(std::get<1>(options.outputChecks), "out");
|
|
||||||
ASSERT_TRUE(output_);
|
|
||||||
auto & output = *output_;
|
|
||||||
|
|
||||||
EXPECT_EQ(output.allowedReferences, StringSet{"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"});
|
|
||||||
EXPECT_EQ(output.allowedRequisites, StringSet{"/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z"});
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto output_ = get(std::get<1>(options.outputChecks), "bin");
|
|
||||||
ASSERT_TRUE(output_);
|
|
||||||
auto & output = *output_;
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
output.disallowedReferences, StringSet{"/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g"});
|
|
||||||
EXPECT_EQ(
|
|
||||||
output.disallowedRequisites, StringSet{"/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8"});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StringSet systemFeatures{"rainbow", "uid-range"};
|
|
||||||
systemFeatures.insert("ca-derivations");
|
|
||||||
|
|
||||||
EXPECT_EQ(options.getRequiredSystemFeatures(got), systemFeatures);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue