-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test framework (#580)
* implement integration testing flow with quickstart * use latest ziti-builder * use ziti cli full path * set ZITI_CONFIG_DIR * check for quickstart readiness
- Loading branch information
Showing
8 changed files
with
225 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,10 @@ runs: | |
run: echo "target = ${{ inputs.target }}" | ||
shell: bash | ||
|
||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20.x' | ||
|
||
- uses: lukka/[email protected] | ||
|
||
- uses: lukka/run-vcpkg@v10 | ||
|
@@ -55,9 +59,8 @@ runs: | |
TEST_ID: ${{ inputs.test_id }} | ||
ZITI_TEST_IDENTITY: ${{ runner.workspace }}/test_id.json | ||
ZITI_LOG: "4" | ||
if: inputs.test == 'true' && inputs.test_id != '' | ||
if: inputs.test == 'true' | ||
working-directory: ./build | ||
shell: bash | ||
run: | | ||
echo "${TEST_ID}" > "${ZITI_TEST_IDENTITY}" | ||
ctest -VV --no-compress-output -R zitilib_tests | ||
ctest -VV --no-compress-output -C ${{ inputs.config }} -R quickstart-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
find_program(EXPECTOR NAMES expect) | ||
if (NOT EXPECTOR) | ||
message(WARNING "expect not found: integration testing is not enabled") | ||
return() | ||
endif () | ||
|
||
execute_process(COMMAND ${EXPECTOR} -v) | ||
|
||
find_program(GOLANG_EXE NAMES go REQUIRED) | ||
|
||
add_executable(integ-tests | ||
main.cpp) | ||
target_link_libraries(integ-tests | ||
PRIVATE ziti | ||
PRIVATE Catch2::Catch2WithMain | ||
) | ||
|
||
if (WIN32) | ||
set_property(TARGET integ-tests PROPERTY CXX_STANDARD 20) | ||
else () | ||
set_property(TARGET integ-tests PROPERTY CXX_STANDARD 14) | ||
endif () | ||
|
||
set(ZITI_CLI_VER "v0.31.0" CACHE STRING "ziti version for integration tests") | ||
add_custom_target(ziti-cli ALL | ||
COMMAND ${CMAKE_COMMAND} -E env GOBIN=${CMAKE_CURRENT_BINARY_DIR} | ||
${GOLANG_EXE} install github.com/openziti/ziti/ziti@${ZITI_CLI_VER} | ||
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/ziti | ||
) | ||
|
||
set(ZITI_CLI ${CMAKE_CURRENT_BINARY_DIR}/ziti) | ||
|
||
set(qs_home ${CMAKE_CURRENT_BINARY_DIR}/qs-home) | ||
add_test(NAME quickstart-bootstrap | ||
COMMAND ${EXPECTOR} ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap.exp | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
COMMAND_EXPAND_LISTS | ||
) | ||
set_tests_properties(quickstart-bootstrap PROPERTIES | ||
FIXTURES_SETUP QS | ||
ENVIRONMENT "ZITI_CLI=${ZITI_CLI};ZITI_CONFIG_DIR=${qs_home};QUICKSTART_HOME=${qs_home};ENROLLER=$<TARGET_FILE:sample_enroll>" | ||
DEPENDS "sample_enroll;ziti-cli" | ||
) | ||
|
||
add_test(NAME quickstart-test | ||
COMMAND ${EXPECTOR} ${CMAKE_CURRENT_SOURCE_DIR}/integ-test.exp | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
set_tests_properties(quickstart-test PROPERTIES | ||
FIXTURES_REQUIRED QS | ||
DEPENDS "integ-tests" | ||
ENVIRONMENT "ZITI_CLI=${ZITI_CLI};ZITI_CONFIG_DIR=${qs_home};QUICKSTART_HOME=${qs_home};TEST_EXE=$<TARGET_FILE:integ-tests>" | ||
) | ||
|
||
add_test(NAME quickstart-cleanup | ||
COMMAND rm -rf ${qs_home} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
set_tests_properties(quickstart-cleanup PROPERTIES FIXTURES_CLEANUP QS) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!expect | ||
|
||
set timeout 20 | ||
proc abort errs { | ||
puts "test failed: $errs" | ||
exit 2 | ||
} | ||
set ziti $env(ZITI_CLI) | ||
puts "ziti = $ziti" | ||
|
||
set enroller $env(ENROLLER) | ||
puts "enroller = $env(ENROLLER)" | ||
|
||
puts "Starting Ziti Quickstart" | ||
puts "========================" | ||
|
||
spawn $ziti edge quickstart --home $env(QUICKSTART_HOME) | ||
set qs_id @spawn_id | ||
# wait until ER is connected | ||
expect { | ||
"finished sychronizing api sessions" { } | ||
timeout { error "qs not started in time" } | ||
eof { error "qs not started" } | ||
} | ||
|
||
puts "Configure model" | ||
puts "===============" | ||
log_user 1 | ||
|
||
expect_before { | ||
timeout { abort "timeout" } | ||
"connection refused" { abort "QS not started" } | ||
} | ||
|
||
spawn $ziti edge create identity test-client -a client -o test-client.jwt | ||
expect { | ||
"New identity test-client created" {} | ||
"error" { abort $expect_out(buffer) } | ||
eof { abort "unexpected" } | ||
} | ||
|
||
spawn $ziti edge create identity test-server -a server -o test-server.jwt | ||
expect { | ||
"New identity test-server created" {} | ||
"error" { error $expect_out(buffer) } | ||
} | ||
|
||
spawn $ziti edge create service test-service | ||
expect { | ||
"New service test-service created" { } | ||
-re "error(.*)" { error $expect_out(1,string) } | ||
eof { error "not cool" } | ||
} | ||
|
||
spawn $ziti edge create service-policy servers-bind Bind --identity-roles \#server --service-roles \#all | ||
expect { | ||
"New service policy servers-bind created" {} | ||
-re "error(.*)" { error $expect_out(1,string) } | ||
eof { error "not cool" } | ||
} | ||
|
||
spawn $ziti edge create service-policy clients-dial Dial --identity-roles \#client --service-roles \#all | ||
expect { | ||
"New service policy clients-dial created" {} | ||
-re "error(.*)" { error $expect_out(1,string) } | ||
eof { error "not cool" } | ||
} | ||
|
||
spawn $enroller ./test-server.jwt ./test-server.json | ||
expect { | ||
"ziti identity is saved in ./test-server.json" {} | ||
eof { error "test-server not enrolled" } | ||
} | ||
|
||
spawn $enroller ./test-client.jwt ./test-client.json | ||
expect { | ||
"ziti identity is saved in ./test-client.json" {} | ||
eof { error "test-client not enrolled" } | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!expect | ||
|
||
set ziti $env(ZITI_CLI) | ||
puts "ziti = $ziti" | ||
|
||
set tester $env(TEST_EXE) | ||
puts "test driver = $tester" | ||
|
||
puts "Starting Ziti Quickstart" | ||
puts "========================" | ||
spawn $ziti edge quickstart --already-initialized --home $env(QUICKSTART_HOME) | ||
set qs_id $spawn_id | ||
|
||
expect { | ||
"finished sychronizing api sessions" { } | ||
timeout { error "qs not started in time" } | ||
eof { error "qs not started" } | ||
} | ||
|
||
spawn $tester | ||
expect { | ||
-re "test cases: (.*) failed" { error "$expect_out(1,string)" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Copyright NetFoundry Inc. | ||
// | ||
// 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 | ||
// | ||
// https://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 <catch2/catch_all.hpp> | ||
#include <ziti/zitilib.h> | ||
#include <ziti/ziti.h> | ||
|
||
class ZitilibManager: public Catch::EventListenerBase{ | ||
|
||
public: | ||
using Catch::EventListenerBase::EventListenerBase; | ||
|
||
void testRunStarting(Catch::TestRunInfo const &) override { | ||
Ziti_lib_init(); | ||
} | ||
|
||
void testRunEnded(const Catch::TestRunStats &testRunStats) override { | ||
Ziti_lib_shutdown(); | ||
} | ||
}; | ||
|
||
CATCH_REGISTER_LISTENER(ZitilibManager) | ||
|
||
TEST_CASE("version", "[integ]") { | ||
const ziti_version *version = ziti_get_version(); | ||
REQUIRE(version != nullptr); | ||
} |