From 17238f77257ca85dc9d8bac8bb7bb4c283521323 Mon Sep 17 00:00:00 2001 From: Florian Spreckelsen <f.spreckelsen@indiscale.com> Date: Wed, 25 Aug 2021 09:31:55 +0000 Subject: [PATCH] ENH: Test queries and entity retrieval --- .gitlab-ci.yml | 1 + CHANGELOG.md | 1 + Project.toml | 2 +- README_SETUP.md | 9 ++++-- test/runtests.jl | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0c80159..c8f19c4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,6 +41,7 @@ variables: DEFAULT_CAOSDB_TAG: f-grpc # The defalt branch to use with caosdb-cpplib + # TODO: Change back to dev once f-consolidate-c has been merged CPP_DEFAULT_BRANCH: dev stages: diff --git a/CHANGELOG.md b/CHANGELOG.md index be0861b..f9364dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Basic CI infrastructure * Simple test for the connection to a CaosDB server * Tests for connecting via config files +* Tests for queries and retrievals by id(s) ### Changed diff --git a/Project.toml b/Project.toml index 497c178..ac89e4b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,4 +1,4 @@ name = "CaosDBIntegrationTests" uuid = "c3438055-fe44-4932-b8ed-926ba38cadad" authors = ["florian <f.spreckelsen@inidscale.com>"] -version = "0.0.1" +version = "0.0.3" diff --git a/README_SETUP.md b/README_SETUP.md index 60a4f28..eef1b21 100644 --- a/README_SETUP.md +++ b/README_SETUP.md @@ -3,15 +3,16 @@ Start a CaosDB server, for now in `f-grpc-dev` branch and set the `CAOSDB_SERVER_HOST`, `CAOSDB_SERVER_GRPC_PORT_HTTPS`, `CAOSDB_SERVER_CERT`, `CAOSDB_USER`, and `CAOSDB_PASSWORD` -environmental variable in such a way that a connection can be established with CaosDB.jl by +environmental variables in such a way that a connection can be established with CaosDB.jl by ```julia using CaosDB CaosDB.Connection.connect_manually() ``` -i.e., without any explicit arguments to the call to -`connect_manually`. Also set up a `caosdb_client.json` either in with +i.e., without any explicit arguments to the call to `connect_manually`. + +Also set up a `caosdb_client.json` with a connection named `julialib-integrationtest` as default that connects to the above server. See the [documentation of libcaosdb](https://docs.indiscale.com/caosdb-cpplib/) for more @@ -20,6 +21,8 @@ information on the config file. # Tests ## Testing against a remote CaosDB.jl +This will fetch a version of CaosDB.jl from the remote server and use it. For +an alternative using a local version see below. After set-up, the integration tests can be executed by diff --git a/test/runtests.jl b/test/runtests.jl index c1294a9..66c86a7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -65,4 +65,76 @@ end @test CaosDB.Connection.connect_manually() != nothing end + @testset "Test transaction" begin + + # transactions can be created from connection names or objects + connection = CaosDB.Connection.connect() + @test create_transaction(connection) != nothing + + @test create_transaction() != nothing + @test create_transaction("julialib-integrationtest") != nothing + + # Construct and execute a transaction manually + transaction = create_transaction() + add_query(transaction, "FIND ENTITY WITH id=-1") + execute(transaction) + result_set = get_result_set(transaction) + results = get_results(result_set) + # There is no entity with id=-1 + @test length(results) == 0 + # result-sets can be omitted + transaction_results = get_results(transaction) + @test length(transaction_results) == 0 + # No count query, so this should be -1 + @test get_count_result(transaction) == -1 + + # Also works directly, with or without connection being + # specified. + query_results1 = execute_query("FIND ENTITY WITH id=-1") + @test length(query_results1) == 0 + query_results2 = execute_query("FIND ENTITY WITH id=-1", "julialib-integrationtest") + @test length(query_results2) == 0 + query_results3 = execute_query("FIND ENTITY WITH id=-1", connection) + @test length(query_results3) == 0 + + # COUNT queries have to be conducted manually + count_transaction = create_transaction() + add_query(count_transaction, "COUNT ENTITY WITH id=-1") + execute(count_transaction) + # Still an empty result set + @test get_count_result(count_transaction) == 0 + end + + @testset "Test entity retrieval" begin + + single_retrieve_transaction = create_transaction() + add_retrieve_by_id(single_retrieve_transaction, "20") + execute(single_retrieve_transaction) + results = get_results(single_retrieve_transaction) + @test length(results) == 1 + @test has_errors(results[1]) == false + @test get_name(results[1]) == "name" + + multi_retrieve_transaction = create_transaction() + add_retrieve_by_id(multi_retrieve_transaction, ["20", "21"]) + execute(multi_retrieve_transaction) + results = get_results(multi_retrieve_transaction) + @test length(results) == 2 + @test get_name(results[1]) == "name" + @test get_name(results[2]) == "unit" + + # Helper functions + ent = retrieve("20") + @test get_name(ent) == "name" + + results = retrieve(["20", "21"]) + @test length(results) == 2 + @test get_name(results[1]) == "name" + @test get_name(results[2]) == "unit" + + # id=22 doesn't exist + @test_throws CaosDB.Exceptions.GenericCaosDBException retrieve("22") + @test_throws CaosDB.Exceptions.GenericCaosDBException retrieve(["20", "21", "22"]) + end + end -- GitLab