Skip to content

Commit

Permalink
move test into new unit-test-libsinsp (#1557)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanseay authored Dec 8, 2019
1 parent 085a99d commit f17d02e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 29 deletions.
4 changes: 3 additions & 1 deletion userspace/libsinsp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
#

include_directories("${GTEST_INCLUDE_DIR}")
include_directories("..")

add_executable(unit-test-libsinsp
testy_test_face.ut.cpp
cgroup_list_counter.ut.cpp
)

target_link_libraries(unit-test-libsinsp
"${GTEST_MAIN_LIB}"
sinsp
)

add_custom_target(run-unit-test-libsinsp
Expand Down
65 changes: 65 additions & 0 deletions userspace/libsinsp/test/cgroup_list_counter.ut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright (C) 2019 Sysdig Inc.
This file is part of sysdig.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <gtest.h>
#include <cgroup_list_counter.h>

TEST(cgroup_list_counter_test, basic)
{
libsinsp::cgroup_list_counter counter;
ASSERT_EQ(8, counter("0-5,8,14"));
ASSERT_EQ(1, counter("5"));
ASSERT_EQ(6, counter("9-14"));
}

TEST(cgroup_list_counter_test, invalid_value)
{
libsinsp::cgroup_list_counter counter;
ASSERT_EQ(-1, counter(""));
ASSERT_EQ(-1, counter(",1"));
}

TEST(cgroup_list_counter_test, invalid_range_missing_number)
{
libsinsp::cgroup_list_counter counter;
ASSERT_EQ(-1, counter("-5,8,14"));
ASSERT_EQ(-1, counter("1,-5,8,14"));
ASSERT_EQ(-1, counter("1,4-,14"));
ASSERT_EQ(-1, counter("1,4-"));
}

TEST(cgroup_list_counter_test, invalid_range_double_dash)
{
libsinsp::cgroup_list_counter counter;
ASSERT_EQ(-1, counter("1,4-5-6,14"));
}

TEST(cgroup_list_counter_test, invalid_range_wrong_order)
{
libsinsp::cgroup_list_counter counter;
ASSERT_EQ(-1, counter("1,6-5,14"));
}

TEST(cgroup_list_counter_test, not_a_number)
{
libsinsp::cgroup_list_counter counter;
ASSERT_EQ(-1, counter("1,5-a,14"));
}


28 changes: 0 additions & 28 deletions userspace/libsinsp/test/testy_test_face.ut.cpp

This file was deleted.

0 comments on commit f17d02e

Please sign in to comment.