mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
increased test coverage
This commit is contained in:
parent
b3ec92b202
commit
71a8c30d36
@ -1,5 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfuse/adapter/credentials.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include <jansson.h>
|
||||
|
||||
@ -8,7 +9,7 @@ TEST(Credentials, Type)
|
||||
struct wf_credentials creds;
|
||||
|
||||
wf_impl_credentials_init(&creds, "test", nullptr);
|
||||
ASSERT_STREQ("test", wf_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ("test", wf_credentials_type(&creds));
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
@ -20,9 +21,9 @@ TEST(Credentials, Get)
|
||||
json_object_set_new(data, "password", json_string("<secret>"));
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ("bob", wf_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ("<secret>", wf_impl_credentials_get(&creds, "password"));
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ("bob", wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ("<secret>", wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
@ -34,9 +35,9 @@ TEST(Credentials, FailedToGetNonexistingValue)
|
||||
json_t * data = json_object();
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password"));
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
@ -47,9 +48,9 @@ TEST(Credentials, FailedToGetWithoutData)
|
||||
struct wf_credentials creds;
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
ASSERT_STREQ("username", wf_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password"));
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
@ -60,11 +61,25 @@ TEST(Credentials, FailedToGetWrongDataType)
|
||||
json_t * data = json_string("invalid_creds");
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password"));
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
TEST(Credentials, FailedToGetWrongElementDataType)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
json_t * data = json_object();
|
||||
json_object_set_new(data, "username", json_integer(42));
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user