1 /*
2    Copyright 2013-2014 EditShare, 2013-2015 Skytechnology sp. z o.o.
3 
4    This file is part of LizardFS.
5 
6    LizardFS is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, version 3.
9 
10    LizardFS is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "common/platform.h"
20 #include "mount/io_limit_group.h"
21 
22 #include <sstream>
23 #include <gtest/gtest.h>
24 
TEST(IoLimitGroupTests,Empty)25 TEST(IoLimitGroupTests, Empty) {
26 	std::stringstream input("");
27 	EXPECT_THROW(getIoLimitGroupId(input, "blkio"), GetIoLimitGroupIdException);
28 }
29 
TEST(IoLimitGroupTests,NoMatching)30 TEST(IoLimitGroupTests, NoMatching) {
31 	std::stringstream input("123:foo,bar:/test\n234:baz:/rmrfHOME\n");
32 	EXPECT_THROW(getIoLimitGroupId(input, "blkio"), GetIoLimitGroupIdException);
33 }
34 
TEST(IoLimitGroupTests,SubsystemSuffix)35 TEST(IoLimitGroupTests, SubsystemSuffix) {
36 	std::stringstream input("123:blkioo:/test");
37 	EXPECT_THROW(getIoLimitGroupId(input, "blkio"), GetIoLimitGroupIdException);
38 }
39 
TEST(IoLimitGroupTests,SubsystemPrefix)40 TEST(IoLimitGroupTests, SubsystemPrefix) {
41 	std::stringstream input("123:bblkio:/test");
42 	EXPECT_THROW(getIoLimitGroupId(input, "blkio"), GetIoLimitGroupIdException);
43 }
44 
TEST(IoLimitGroupTests,Minimal)45 TEST(IoLimitGroupTests, Minimal) {
46 	std::stringstream input(":blkio:/test\n");
47 	EXPECT_EQ(getIoLimitGroupId(input, "blkio"), "/test");
48 }
49 
TEST(IoLimitGroupTests,Commas)50 TEST(IoLimitGroupTests, Commas) {
51 	std::stringstream input("123:cpuset,blkio,memory:/test\n");
52 	EXPECT_EQ(getIoLimitGroupId(input, "blkio"), "/test");
53 }
54 
TEST(IoLimitGroupTests,SecondLine)55 TEST(IoLimitGroupTests, SecondLine) {
56 	std::stringstream input("1:blah:/wrong\n:blkio:/test\n");
57 	EXPECT_EQ(getIoLimitGroupId(input, "blkio"), "/test");
58 }
59