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

Use lowercase resource and owner names when storing assets on disk #130

Merged
merged 8 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
72 changes: 36 additions & 36 deletions src/FuelClient_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ TEST_F(FuelClientTest, ParseModelURL)
EXPECT_EQ(id.Server().Url().Str(), "https://some.example.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 0u);
}

Expand All @@ -166,7 +166,7 @@ TEST_F(FuelClientTest, ParseModelURL)
EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 4u);
}

Expand All @@ -185,7 +185,7 @@ TEST_F(FuelClientTest, ParseModelURL)
EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 6u);
}

Expand All @@ -202,7 +202,7 @@ TEST_F(FuelClientTest, ParseModelURL)
EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_FALSE(id.Server().Version().empty());
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 0u);
}

Expand All @@ -221,7 +221,7 @@ TEST_F(FuelClientTest, ParseModelURL)
EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 0u);
}

Expand Down Expand Up @@ -292,8 +292,8 @@ TEST_F(FuelClientTest, ParseModelFileURL)

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Cordless Drill");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "cordless drill");
EXPECT_EQ(filePath, "meshes/cordless_drill.dae");
}

Expand All @@ -305,14 +305,14 @@ TEST_F(FuelClientTest, ParseModelFileURL)
ModelIdentifier id;
std::string filePath;
const common::URI modelUrl{
"https://fuel.ignitionrobotics.org/1.0/OpenRobotics/models/Pine Tree/tip/"
"https://fuel.ignitionrobotics.org/1.0/openrobotics/models/Pine Tree/tip/"
"files/materials/scripts/pine_tree.material"};
EXPECT_TRUE(client.ParseModelFileUrl(modelUrl, id, filePath));

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Pine Tree");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "pine tree");
EXPECT_EQ(filePath, "materials/scripts/pine_tree.material");
}

Expand All @@ -330,8 +330,8 @@ TEST_F(FuelClientTest, ParseModelFileURL)

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Pine Tree");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "pine tree");
EXPECT_EQ(filePath, "model.sdf");
}

Expand All @@ -341,15 +341,15 @@ TEST_F(FuelClientTest, ParseModelFileURL)
ModelIdentifier id;
std::string filePath;
const common::URI modelUrl{
"https://fuel.ignitionrobotics.org/OpenRobotics/models/Pine Tree/tip/"
"https://fuel.ignitionrobotics.org/OpenRobotics/models/pine tree/tip/"
"files/materials/scripts/pine_tree.material"};
EXPECT_TRUE(client.ParseModelFileUrl(modelUrl, id, filePath));

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_FALSE(id.Server().Version().empty());
EXPECT_EQ("1.0", id.Server().Version());
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Pine Tree");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "pine tree");
EXPECT_EQ(filePath, "materials/scripts/pine_tree.material");
}

Expand All @@ -361,14 +361,14 @@ TEST_F(FuelClientTest, ParseModelFileURL)
ModelIdentifier id;
std::string filePath;
const common::URI modelUrl{
"https://fuel.ignitionrobotics.org/OpenRobotics/models/Pine Tree/tip/"
"https://fuel.ignitionrobotics.org/openrobotics/models/Pine Tree/tip/"
"files/materials/scripts/pine_tree.material"};
EXPECT_TRUE(client.ParseModelFileUrl(modelUrl, id, filePath));

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Pine Tree");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "pine tree");
EXPECT_EQ(filePath, "materials/scripts/pine_tree.material");
}

Expand Down Expand Up @@ -427,7 +427,7 @@ TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadModel))

// Check it was downloaded to `2`
auto modelPath = common::joinPaths(common::cwd(), "test_cache",
"fuel.ignitionrobotics.org", "chapulina", "models", "Test box");
"fuel.ignitionrobotics.org", "chapulina", "models", "test box");

EXPECT_EQ(path, common::joinPaths(modelPath, "2"));
EXPECT_TRUE(common::exists(common::joinPaths(modelPath, "2")));
Expand Down Expand Up @@ -465,7 +465,7 @@ TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadModel))

// Check it was downloaded to `2`
auto modelPath = common::joinPaths(common::cwd(), "test_cache",
"fuel.ignitionrobotics.org", "iche033", "models", "Rescue Randy");
"fuel.ignitionrobotics.org", "iche033", "models", "rescue randy");

EXPECT_EQ(path, common::joinPaths(modelPath, "2"));
EXPECT_TRUE(common::exists(common::joinPaths(modelPath, "2")));
Expand Down Expand Up @@ -668,7 +668,7 @@ TEST_F(FuelClientTest, ParseWorldUrl)
EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 0u);
}

Expand All @@ -687,7 +687,7 @@ TEST_F(FuelClientTest, ParseWorldUrl)
EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 4u);
}

Expand All @@ -706,7 +706,7 @@ TEST_F(FuelClientTest, ParseWorldUrl)
EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 6u);
}

Expand All @@ -724,7 +724,7 @@ TEST_F(FuelClientTest, ParseWorldUrl)
EXPECT_FALSE(id.Server().Version().empty());
EXPECT_EQ("1.0", id.Server().Version());
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 0u);
}

Expand All @@ -743,7 +743,7 @@ TEST_F(FuelClientTest, ParseWorldUrl)
EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "german");
EXPECT_EQ(id.Name(), "Cardboard Box");
EXPECT_EQ(id.Name(), "cardboard box");
EXPECT_EQ(id.Version(), 0u);
}

Expand Down Expand Up @@ -811,8 +811,8 @@ TEST_F(FuelClientTest, ParseWorldFileUrl)

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Empty");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "empty");
EXPECT_EQ(filePath, "test.world");
}

Expand All @@ -830,8 +830,8 @@ TEST_F(FuelClientTest, ParseWorldFileUrl)

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Empty sky");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "empty sky");
EXPECT_EQ(filePath, "empty_sky.world");
}

Expand All @@ -849,8 +849,8 @@ TEST_F(FuelClientTest, ParseWorldFileUrl)

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Empty");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "empty");
EXPECT_EQ(filePath, "test.world");
}

Expand All @@ -867,8 +867,8 @@ TEST_F(FuelClientTest, ParseWorldFileUrl)
EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_FALSE(id.Server().Version().empty());
EXPECT_EQ("1.0", id.Server().Version());
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Empty sky");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "empty sky");
EXPECT_EQ(filePath, "empty_sky.world");
}

Expand All @@ -886,8 +886,8 @@ TEST_F(FuelClientTest, ParseWorldFileUrl)

EXPECT_EQ(id.Server().Url().Str(), "https://fuel.ignitionrobotics.org");
EXPECT_EQ(id.Server().Version(), "1.0");
EXPECT_EQ(id.Owner(), "OpenRobotics");
EXPECT_EQ(id.Name(), "Empty");
EXPECT_EQ(id.Owner(), "openrobotics");
EXPECT_EQ(id.Name(), "empty");
EXPECT_EQ(filePath, "test.world");
}

Expand Down Expand Up @@ -952,7 +952,7 @@ TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadWorld))

// Check it was downloaded to `1`
auto worldPath = common::joinPaths(common::cwd(), "test_cache",
"fuel.ignitionrobotics.org", "OpenRobotics", "worlds", "Test world");
"fuel.ignitionrobotics.org", "openrobotics", "worlds", "test world");

EXPECT_EQ(path, common::joinPaths(worldPath, "2"));
EXPECT_TRUE(common::exists(common::joinPaths(worldPath, "2")));
Expand Down
13 changes: 8 additions & 5 deletions src/ModelIdentifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <ignition/common/Console.hh>
#include <ignition/common/Filesystem.hh>
#include <ignition/common/Util.hh>

#include "ignition/fuel_tools/ClientConfig.hh"
#include "ignition/fuel_tools/ModelIdentifier.hh"
Expand Down Expand Up @@ -154,22 +155,24 @@ std::string ModelIdentifier::Name() const
bool ModelIdentifier::SetName(const std::string &_name)
{
bool success = false;
if (this->dataPtr->ValidName(_name))
std::string name = common::lowercase(_name);
if (this->dataPtr->ValidName(name))
{
success = true;
this->dataPtr->name = _name;
this->dataPtr->name = name;
}
return success;
}

//////////////////////////////////////////////////
bool ModelIdentifier::SetOwner(const std::string &_name)
bool ModelIdentifier::SetOwner(const std::string &_owner)
{
bool success = false;
if (this->dataPtr->ValidName(_name))
std::string owner = common::lowercase(_owner);
if (this->dataPtr->ValidName(owner))
{
success = true;
this->dataPtr->owner = _name;
this->dataPtr->owner = owner;
}
return success;
}
Expand Down
7 changes: 4 additions & 3 deletions src/WorldIdentifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <vector>

#include <ignition/common/Filesystem.hh>
#include <ignition/common/Util.hh>

#include "ignition/fuel_tools/ClientConfig.hh"
#include "ignition/fuel_tools/WorldIdentifier.hh"
Expand Down Expand Up @@ -93,7 +94,7 @@ std::string WorldIdentifier::Name() const
//////////////////////////////////////////////////
bool WorldIdentifier::SetName(const std::string &_name)
{
this->dataPtr->name = _name;
this->dataPtr->name = common::lowercase(_name);
return true;
}

Expand All @@ -104,9 +105,9 @@ std::string WorldIdentifier::Owner() const
}

//////////////////////////////////////////////////
bool WorldIdentifier::SetOwner(const std::string &_name)
bool WorldIdentifier::SetOwner(const std::string &_owner)
{
this->dataPtr->owner = _name;
this->dataPtr->owner = common::lowercase(_owner);
return true;
}

Expand Down
Loading