Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to #81 #82

Merged
merged 2 commits into from
Jan 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions src/Manager_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,46 @@

#include <gtest/gtest.h>
#include <ignition/common/Console.hh>
#include <ignition/common/Filesystem.hh>

#include <ignition/utilities/ExtraTestMacros.hh>

#include <sys/stat.h>

#include "Manager.hh"

static const std::string kTestScriptPath = "/tmp/ign-launch.sh";

/////////////////////////////////////////////////
bool RemoveTestScript()
{
// Remove the file if it already exists
if (ignition::common::isFile(kTestScriptPath))
{
if (!ignition::common::removeFile(kTestScriptPath))
{
return false;
}
}
return true;
}

/////////////////////////////////////////////////
bool WriteTestScript()
{
if (!RemoveTestScript())
return false;

// Write a simple script and mark it executable
std::ofstream ofs(kTestScriptPath);
ofs << R"(#!/usr/bin/env bash
echo $TEST_VAR
touch $TEST_VAR
)";
chmod(kTestScriptPath.c_str(), S_IRWXU);
return true;
}

/////////////////////////////////////////////////
TEST(Ignition_TEST, RunEmptyConfig)
{
Expand Down Expand Up @@ -81,6 +119,73 @@ TEST(Ignition_TEST, RunLs)
EXPECT_TRUE(mgr.RunConfig(config));
}


/////////////////////////////////////////////////
TEST(Ignition_TEST, IGN_UTILS_TEST_DISABLED_ON_WIN32(RunEnvPre))
{
// Test that environment is applied regardless of order
std::string testPath = "/tmp/ign-launch-env-test-pre";
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved

if (ignition::common::isFile(testPath))
{
ASSERT_TRUE(ignition::common::removeFile(testPath));
}

ASSERT_TRUE(WriteTestScript());

std::string config = R"(
<ignition version='1.0'>
<env>
<name>TEST_VAR</name>
<value>)" + testPath + R"(</value>
</env>
<executable name='touch'>
<command>/tmp/ign-launch.sh</command>
</executable>
</ignition>
)";

ignition::launch::Manager mgr;

EXPECT_TRUE(mgr.RunConfig(config));
EXPECT_TRUE(ignition::common::isFile(testPath));
EXPECT_TRUE(ignition::common::removeFile(testPath));
EXPECT_TRUE(RemoveTestScript());
}

/////////////////////////////////////////////////
TEST(Ignition_TEST, IGN_UTILS_TEST_DISABLED_ON_WIN32(RunEnvPost))
{
// Test that environment is applied regardless of order
std::string testPath = "/tmp/ign-launch-env-test-post";

if (ignition::common::isFile(testPath))
{
ASSERT_TRUE(ignition::common::removeFile(testPath));
}

ASSERT_TRUE(WriteTestScript());

std::string config = R"(
<ignition version='1.0'>
<executable name='touch'>
<command>/tmp/ign-launch.sh</command>
</executable>
<env>
<name>TEST_VAR</name>
<value>)" + testPath + R"(</value>
</env>
</ignition>
)";

ignition::launch::Manager mgr;

EXPECT_TRUE(mgr.RunConfig(config));
EXPECT_TRUE(ignition::common::isFile(testPath));
EXPECT_TRUE(ignition::common::removeFile(testPath));
EXPECT_TRUE(RemoveTestScript());
}

/////////////////////////////////////////////////
int main(int argc, char **argv)
{
Expand Down