Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cppinttest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cppinttest
Commits
f58a0d8e
Verified
Commit
f58a0d8e
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: retrieve simple entity
parent
a305c136
No related branches found
No related tags found
No related merge requests found
Pipeline
#10004
failed
3 years ago
Stage: info
Stage: setup
Stage: build
Stage: test
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
test/CMakeLists.txt
+6
-4
6 additions, 4 deletions
test/CMakeLists.txt
test/test_connection.cpp
+6
-20
6 additions, 20 deletions
test/test_connection.cpp
test/test_connection.h
+85
-0
85 additions, 0 deletions
test/test_connection.h
test/test_transaction.cpp
+5
-16
5 additions, 16 deletions
test/test_transaction.cpp
with
102 additions
and
40 deletions
test/CMakeLists.txt
+
6
−
4
View file @
f58a0d8e
...
...
@@ -79,10 +79,12 @@ foreach (i RANGE "${len_test_cases}")
${
CONAN_LIBS_PROTOBUF
}
${
CONAN_LIBS_ZLIB
}
${
CONAN_LIBS_RE2
}
)
target_include_directories
(
${
test_case_name
}
PUBLIC
${
CONAN_INCLUDE_DIRS
}
${
CMAKE_CURRENT_SOURCE_DIR
}
)
set_target_properties
(
${
test_case_name
}
PROPERTIES
CXX_CLANG_TIDY
"
${
_CMAKE_CXX_CLANG_TIDY
}
;
${
_CMAKE_CXX_CLANG_TIDY_CHECKS
}
"
CXX_INCLUDE_WHAT_YOU_USE
"
${
_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
}
"
)
if
(
LINTING
)
set_target_properties
(
${
test_case_name
}
PROPERTIES
CXX_CLANG_TIDY
"
${
_CMAKE_CXX_CLANG_TIDY
}
;
${
_CMAKE_CXX_CLANG_TIDY_CHECKS
}
"
CXX_INCLUDE_WHAT_YOU_USE
"
${
_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
}
"
)
endif
()
gtest_discover_tests
(
${
test_case_name
}
PROPERTIES
LABELS
"caosdb-cpplib-int-tests"
)
...
...
This diff is collapsed.
Click to expand it.
test/test_connection.cpp
+
6
−
20
View file @
f58a0d8e
/*
*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
...
...
@@ -30,6 +29,7 @@
#include
"caosdb/utils.h"
// for get_env_var
#include
"gtest/gtest_pred_impl.h"
// for Test, TEST, EXPECT_EQ, EXPECT_THROW
#include
"caosdb_test_utility.h"
#include
"test_connection.h"
namespace
caosdb
::
connection
{
using
caosdb
::
authentication
::
PlainPasswordAuthenticator
;
...
...
@@ -74,7 +74,7 @@ TEST(test_connection, connection_ssl_authentication_error_anonymous) {
const
auto
host
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_HOST"
,
"localhost"
);
const
auto
path
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_C
A_PEM
"
,
std
::
string
());
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_C
ERT
"
,
std
::
string
());
auto
ssloptions
=
std
::
make_shared
<
PemFileCACertProvider
>
(
path
);
auto
config
=
...
...
@@ -82,7 +82,7 @@ TEST(test_connection, connection_ssl_authentication_error_anonymous) {
auto
connection
=
CaosDBConnection
(
config
);
EXPECT_THROW_MESSAGE
(
connection
.
GetVersionInfo
(),
AuthenticationError
,
"Please
L
ogin."
);
"Please
l
ogin."
);
}
TEST
(
test_connection
,
connection_ssl_authentication_error_wrong_credentials
)
{
...
...
@@ -92,7 +92,7 @@ TEST(test_connection, connection_ssl_authentication_error_wrong_credentials) {
const
auto
host
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_HOST"
,
"localhost"
);
const
auto
path
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_C
A_PEM
"
,
std
::
string
());
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_C
ERT
"
,
std
::
string
());
const
auto
*
const
user
=
"not-a-user-23461237"
;
const
auto
*
const
password
=
"very-c-cred"
;
...
...
@@ -107,27 +107,13 @@ TEST(test_connection, connection_ssl_authentication_error_wrong_credentials) {
}
TEST
(
test_connection
,
connection_ssl_authentication_success
)
{
auto
port_str
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_GRPC_PORT_HTTPS"
,
"8443"
);
auto
port
=
std
::
stoi
(
port_str
);
const
auto
host
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_HOST"
,
"localhost"
);
const
auto
path
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_CA_PEM"
,
std
::
string
());
const
auto
user
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_USER"
,
"admin"
);
const
auto
password
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_PASSWORD"
,
"caosdb"
);
auto
pConnection
=
get_test_connection
();
auto
major
=
0
;
auto
minor
=
5
;
const
auto
*
const
pre_release
=
"GRPC004"
;
auto
auth
=
std
::
make_shared
<
PlainPasswordAuthenticator
>
(
user
,
password
);
auto
ssloptions
=
std
::
make_shared
<
PemFileCACertProvider
>
(
path
);
auto
config
=
std
::
make_shared
<
SslCaosDBConnectionConfig
>
(
host
,
port
,
ssloptions
,
auth
);
auto
connection
=
CaosDBConnection
(
config
);
auto
v_info
=
connection
.
GetVersionInfo
();
auto
v_info
=
pConnection
->
GetVersionInfo
();
EXPECT_EQ
(
major
,
v_info
->
GetMajor
());
EXPECT_EQ
(
minor
,
v_info
->
GetMinor
());
EXPECT_EQ
(
pre_release
,
v_info
->
GetPreRelease
());
...
...
This diff is collapsed.
Click to expand it.
test/test_connection.h
0 → 100644
+
85
−
0
View file @
f58a0d8e
/*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include
<gtest/gtest-message.h>
// for Message
#include
<gtest/gtest-test-part.h>
// for SuiteApiResolver, TestPartResult
#include
<memory>
// for make_shared, allocator, shared_ptr
#include
<string>
// for string
#include
"caosdb/authentication.h"
// for PlainPasswordAuthenticator
#include
"caosdb/connection.h"
// for InsecureCaosDBConnectionConfig
#include
"caosdb/exceptions.h"
// for AuthenticationError, ConnectionError
#include
"caosdb/info.h"
// for VersionInfo
#include
"caosdb/utils.h"
// for get_env_var
#include
"gtest/gtest_pred_impl.h"
// for Test, TEST, EXPECT_EQ, EXPECT_THROW
#include
"caosdb_test_utility.h"
namespace
caosdb
::
connection
{
using
caosdb
::
authentication
::
PlainPasswordAuthenticator
;
/**
* Return a fresh CaosDBConnection pointer. The caller has the ownership.
*/
inline
auto
create_test_connection
()
->
CaosDBConnection
*
{
auto
port_str
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_GRPC_PORT_HTTPS"
,
"8443"
);
auto
port
=
std
::
stoi
(
port_str
);
const
auto
host
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_HOST"
,
"localhost"
);
const
auto
path
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_CERT"
,
std
::
string
());
const
auto
user
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_USER"
,
"admin"
);
const
auto
password
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_PASSWORD"
,
"caosdb"
);
auto
auth
=
std
::
make_shared
<
PlainPasswordAuthenticator
>
(
user
,
password
);
auto
ssloptions
=
std
::
make_shared
<
PemFileCACertProvider
>
(
path
);
auto
config
=
std
::
make_shared
<
SslCaosDBConnectionConfig
>
(
host
,
port
,
ssloptions
,
auth
);
return
new
CaosDBConnection
(
config
);
};
/**
* Singleton which holds a single global CaosDBConnection
*/
class
ConnectionProvider
{
private:
std
::
shared_ptr
<
CaosDBConnection
>
connection
;
ConnectionProvider
()
:
connection
(
create_test_connection
()){};
public
:
static
ConnectionProvider
&
GetInstance
()
{
static
ConnectionProvider
instance
;
return
instance
;
};
inline
auto
GetConnection
()
->
std
::
shared_ptr
<
CaosDBConnection
>
&
{
return
this
->
connection
;
}
ConnectionProvider
(
ConnectionProvider
const
&
)
=
delete
;
void
operator
=
(
ConnectionProvider
const
&
)
=
delete
;
};
/**
* Return a connection for testing purposes.
*/
inline
auto
get_test_connection
()
->
const
std
::
shared_ptr
<
CaosDBConnection
>
&
{
return
ConnectionProvider
::
GetInstance
().
GetConnection
();
};
}
// namespace caosdb::connection
This diff is collapsed.
Click to expand it.
test/test_transaction.cpp
+
5
−
16
View file @
f58a0d8e
...
...
@@ -28,29 +28,18 @@
#include
"caosdb/transaction.h"
// for Transaction, UniqueResult, Entity
#include
"caosdb/utils.h"
// for get_env_var
#include
"gtest/gtest_pred_impl.h"
// for Test, TestInfo, EXPECT_EQ, TEST
#include
"test_connection.h"
namespace
caosdb
::
transaction
{
using
caosdb
::
authentication
::
PlainPasswordAuthenticator
;
using
caosdb
::
connection
::
CaosDBConnection
;
using
caosdb
::
connection
::
Insecure
CaosDBConnectionConfig
;
using
caosdb
::
connection
::
Ssl
CaosDBConnectionConfig
;
TEST
(
test_transaction
,
first_test
)
{
auto
port_str
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_GRPC_PORT_HTTP"
,
"8080"
);
auto
port
=
std
::
stoi
(
port_str
);
const
auto
host
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_HOST"
,
"localhost"
);
const
auto
user
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_USER"
,
"admin"
);
const
auto
password
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_PASSWORD"
,
"caosdb"
);
auto
connection
=
caosdb
::
connection
::
get_test_connection
();
const
auto
*
const
description
=
"This is an entity"
;
auto
auth
=
std
::
make_shared
<
PlainPasswordAuthenticator
>
(
user
,
password
);
auto
config
=
std
::
make_shared
<
InsecureCaosDBConnectionConfig
>
(
host
,
port
,
auth
);
auto
connection
=
CaosDBConnection
(
config
);
auto
transaction
(
connection
.
CreateTransaction
());
auto
description
=
"This is an entity"
;
auto
transaction
(
connection
->
CreateTransaction
());
transaction
->
Retrieve
(
caosdb
::
entity
::
EntityID
(
"someid"
));
transaction
->
Execute
();
auto
result_set
(
std
::
static_pointer_cast
<
caosdb
::
transaction
::
UniqueResult
>
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment