|
| 1 | +/* |
| 2 | + * Copyright 2020 New Relic Corporation. All rights reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | +#include "tlib_php.h" |
| 6 | +#include "tlib_datastore.h" |
| 7 | + |
| 8 | +#include "php_agent.h" |
| 9 | +#include "php_memcached.h" |
| 10 | +#include "util_system.h" |
| 11 | + |
| 12 | +tlib_parallel_info_t parallel_info |
| 13 | + = {.suggested_nthreads = -1, .state_size = 0}; |
| 14 | + |
| 15 | +static char* system_host_name; |
| 16 | + |
| 17 | +static void test_create_datastore_instance(void) { |
| 18 | + /* |
| 19 | + * Test : Normal operation. |
| 20 | + */ |
| 21 | + assert_datastore_instance_equals_destroy( |
| 22 | + "named socket", |
| 23 | + &((nr_datastore_instance_t){ |
| 24 | + .host = system_host_name, |
| 25 | + .database_name = "unknown", |
| 26 | + .port_path_or_id = "/tmp/memcached.sock", |
| 27 | + }), |
| 28 | + nr_php_memcached_create_datastore_instance("/tmp/memcached.sock", 0)); |
| 29 | + |
| 30 | + assert_datastore_instance_equals_destroy( |
| 31 | + "empty socket", |
| 32 | + &((nr_datastore_instance_t){ |
| 33 | + .host = system_host_name, |
| 34 | + .database_name = "unknown", |
| 35 | + .port_path_or_id = "unknown", |
| 36 | + }), |
| 37 | + nr_php_memcached_create_datastore_instance("", 0)); |
| 38 | + |
| 39 | + assert_datastore_instance_equals_destroy( |
| 40 | + "empty host", |
| 41 | + &((nr_datastore_instance_t){ |
| 42 | + .host = "unknown", |
| 43 | + .database_name = "unknown", |
| 44 | + .port_path_or_id = "6379", |
| 45 | + }), |
| 46 | + nr_php_memcached_create_datastore_instance("", 6379)); |
| 47 | + |
| 48 | + assert_datastore_instance_equals_destroy( |
| 49 | + "localhost socket", |
| 50 | + &((nr_datastore_instance_t){ |
| 51 | + .host = system_host_name, |
| 52 | + .database_name = "unknown", |
| 53 | + .port_path_or_id = "localhost", |
| 54 | + }), |
| 55 | + nr_php_memcached_create_datastore_instance("localhost", 0)); |
| 56 | + |
| 57 | + assert_datastore_instance_equals_destroy( |
| 58 | + "localhost and port", |
| 59 | + &((nr_datastore_instance_t){ |
| 60 | + .host = system_host_name, |
| 61 | + .database_name = "unknown", |
| 62 | + .port_path_or_id = "6379", |
| 63 | + }), |
| 64 | + nr_php_memcached_create_datastore_instance("localhost", 6379)); |
| 65 | + |
| 66 | + assert_datastore_instance_equals_destroy( |
| 67 | + "host.name socket", |
| 68 | + &((nr_datastore_instance_t){ |
| 69 | + .host = system_host_name, |
| 70 | + .database_name = "unknown", |
| 71 | + .port_path_or_id = "host.name", |
| 72 | + }), |
| 73 | + nr_php_memcached_create_datastore_instance("host.name", 0)); |
| 74 | + |
| 75 | + assert_datastore_instance_equals_destroy( |
| 76 | + "host and port", |
| 77 | + &((nr_datastore_instance_t){ |
| 78 | + .host = "host.name", |
| 79 | + .database_name = "unknown", |
| 80 | + .port_path_or_id = "6379", |
| 81 | + }), |
| 82 | + nr_php_memcached_create_datastore_instance("host.name", 6379)); |
| 83 | +} |
| 84 | + |
| 85 | +void test_main(void* p NRUNUSED) { |
| 86 | +#if defined(ZTS) && !defined(PHP7) |
| 87 | + void*** tsrm_ls = NULL; |
| 88 | +#endif /* ZTS && !PHP7 */ |
| 89 | + |
| 90 | + system_host_name = nr_system_get_hostname(); |
| 91 | + |
| 92 | + test_create_datastore_instance(); |
| 93 | + |
| 94 | + nr_free(system_host_name); |
| 95 | +} |
0 commit comments