diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 82045983..de0da2cf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,7 +14,7 @@ # License for the specific language governing permissions and limitations under # the License. # -set(FALCO_TESTS_SOURCES test_base.cpp engine/test_token_bucket.cpp engine/test_rulesets.cpp falco/test_webserver.cpp) +set(FALCO_TESTS_SOURCES test_base.cpp engine/test_token_bucket.cpp engine/test_rulesets.cpp engine/test_falco_utils.cpp falco/test_webserver.cpp) set(FALCO_TESTED_LIBRARIES falco_engine) diff --git a/tests/engine/test_falco_utils.cpp b/tests/engine/test_falco_utils.cpp new file mode 100644 index 00000000..1f83a7dd --- /dev/null +++ b/tests/engine/test_falco_utils.cpp @@ -0,0 +1,35 @@ +/* +Copyright (C) 2020 The Falco Authors. + +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 "falco_utils.h" +#include + +TEST_CASE("Startswith shold match when checked string has prefix", "[utils]") +{ + bool res = falco::utils::starts_with("unix:///var/run/falco/falco.sock", "unix://"); + REQUIRE(res); +} + +TEST_CASE("Startswith shold not match when checked string does not have prefix", "[utils]") +{ + bool res = falco::utils::starts_with("unix:///var/run/falco/falco.sock", "something://"); + REQUIRE_FALSE(res); +} + +TEST_CASE("Startswith shold not match when prefix is at a random position", "[utils]") +{ + bool res = falco::utils::starts_with("/var/run/unix:///falco.sock", "unix://"); + REQUIRE_FALSE(res); +} diff --git a/userspace/falco/CMakeLists.txt b/userspace/falco/CMakeLists.txt index 9b6e6d26..3b733042 100644 --- a/userspace/falco/CMakeLists.txt +++ b/userspace/falco/CMakeLists.txt @@ -52,7 +52,6 @@ add_executable( grpc_server_impl.cpp grpc_request_context.cpp grpc_server.cpp - utils.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.grpc.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/version.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/output.grpc.pb.cc