mirror of
https://github.com/NixOS/nix.git
synced 2025-12-08 01:51:01 +01:00
93 lines
No EOL
2.2 KiB
C++
93 lines
No EOL
2.2 KiB
C++
#include <gtest/gtest.h>
|
|
#include <gmock/gmock.h>
|
|
|
|
#include "nix/store/globals.hh"
|
|
#include "nix/util/processes.hh"
|
|
#include "nix/util/file-system.hh"
|
|
|
|
#ifdef __linux__
|
|
#include "nix/unix/build/pasta.hh"
|
|
|
|
namespace nix {
|
|
|
|
TEST(PastaTest, ConstantsAreDefined) {
|
|
// Test that all pasta constants are properly defined
|
|
EXPECT_STREQ(pasta::PASTA_NS_IFNAME, "eth0");
|
|
EXPECT_STREQ(pasta::PASTA_HOST_IPV4, "169.254.1.1");
|
|
EXPECT_STREQ(pasta::PASTA_CHILD_IPV4, "169.254.1.2");
|
|
EXPECT_STREQ(pasta::PASTA_PREFIX_IPV4, "30");
|
|
}
|
|
|
|
TEST(PastaTest, RewriteResolvConfBasic) {
|
|
// Test basic resolv.conf rewriting
|
|
std::string original = R"(
|
|
# Generated by NetworkManager
|
|
nameserver 8.8.8.8
|
|
nameserver 8.8.4.4
|
|
search example.com
|
|
)";
|
|
|
|
std::string expected = R"(
|
|
# Generated by NetworkManager
|
|
nameserver 169.254.1.1
|
|
nameserver 169.254.1.1
|
|
search example.com
|
|
)";
|
|
|
|
std::string result = pasta::rewriteResolvConf(original);
|
|
EXPECT_EQ(result, expected);
|
|
}
|
|
|
|
TEST(PastaTest, RewriteResolvConfEmpty) {
|
|
// Test empty resolv.conf
|
|
std::string original = "";
|
|
std::string result = pasta::rewriteResolvConf(original);
|
|
EXPECT_EQ(result, "");
|
|
}
|
|
|
|
TEST(PastaTest, RewriteResolvConfComments) {
|
|
// Test resolv.conf with only comments
|
|
std::string original = R"(# This is a comment
|
|
# Another comment
|
|
)";
|
|
std::string result = pasta::rewriteResolvConf(original);
|
|
EXPECT_EQ(result, original);
|
|
}
|
|
|
|
TEST(PastaTest, RewriteResolvConfMixed) {
|
|
// Test resolv.conf with various directives
|
|
std::string original = R"(
|
|
nameserver 192.168.1.1
|
|
domain local.lan
|
|
search local.lan corp.lan
|
|
nameserver 192.168.1.2
|
|
options ndots:1
|
|
)";
|
|
|
|
std::string expected = R"(
|
|
nameserver 169.254.1.1
|
|
domain local.lan
|
|
search local.lan corp.lan
|
|
nameserver 169.254.1.1
|
|
options ndots:1
|
|
)";
|
|
|
|
std::string result = pasta::rewriteResolvConf(original);
|
|
EXPECT_EQ(result, expected);
|
|
}
|
|
|
|
TEST(PastaTest, SettingIsConfigurable) {
|
|
// Test that pasta path setting can be configured
|
|
Settings settings;
|
|
|
|
// Default should be empty
|
|
EXPECT_EQ(settings.pastaPath.get(), "");
|
|
|
|
// Should be settable
|
|
settings.pastaPath = "/usr/bin/pasta";
|
|
EXPECT_EQ(settings.pastaPath.get(), "/usr/bin/pasta");
|
|
}
|
|
|
|
} // namespace nix
|
|
|
|
#endif // __linux__
|