-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetailed_test.zig
More file actions
78 lines (52 loc) · 2.4 KB
/
Copy pathdetailed_test.zig
File metadata and controls
78 lines (52 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const std = @import("std");
const testing = std.testing;
const c = @cImport({
@cInclude("libcouchbase/couchbase.h");
});
fn fromStatusCode(rc: c.lcb_STATUS) !void {
if (rc == c.LCB_SUCCESS) return;
return error.Unknown;
}
test "detailed connection" {
std.debug.print("\n=== Starting detailed connection test ===\n", .{});
const allocator = testing.allocator;
const conn_str_z = try allocator.dupeZ(u8, "couchbase://127.0.0.1");
defer allocator.free(conn_str_z);
std.debug.print("1. Allocated conn string\n", .{});
var create_opts: ?*c.lcb_CREATEOPTS = null;
_ = c.lcb_createopts_create(&create_opts, c.LCB_TYPE_BUCKET);
defer _ = c.lcb_createopts_destroy(create_opts);
std.debug.print("2. Created opts\n", .{});
_ = c.lcb_createopts_connstr(create_opts, conn_str_z.ptr, conn_str_z.len);
std.debug.print("3. Set connection string\n", .{});
const username_z = try allocator.dupeZ(u8, "tester");
defer allocator.free(username_z);
const password_z = try allocator.dupeZ(u8, "csfb2010");
defer allocator.free(password_z);
_ = c.lcb_createopts_credentials(create_opts, username_z.ptr, username_z.len, password_z.ptr, password_z.len);
std.debug.print("4. Set credentials\n", .{});
const bucket_z = try allocator.dupeZ(u8, "default");
defer allocator.free(bucket_z);
_ = c.lcb_createopts_bucket(create_opts, bucket_z.ptr, bucket_z.len);
std.debug.print("5. Set bucket\n", .{});
var instance: ?*c.lcb_INSTANCE = null;
var rc = c.lcb_create(&instance, create_opts);
try fromStatusCode(rc);
std.debug.print("6. Created instance\n", .{});
const inst = instance orelse return error.ConnectionFailed;
var timeout_ms: u32 = 10000;
_ = c.lcb_cntl(inst, c.LCB_CNTL_SET, c.LCB_CNTL_CONFIGURATION_TIMEOUT, &timeout_ms);
std.debug.print("7. Set timeout\n", .{});
rc = c.lcb_connect(inst);
try fromStatusCode(rc);
std.debug.print("8. Called connect\n", .{});
rc = c.lcb_wait(inst, 0);
try fromStatusCode(rc);
std.debug.print("9. Waited\n", .{});
rc = c.lcb_get_bootstrap_status(inst);
try fromStatusCode(rc);
std.debug.print("10. Got bootstrap status\n", .{});
c.lcb_destroy(inst);
std.debug.print("11. Destroyed instance\n", .{});
std.debug.print("=== Test completed ===\n", .{});
}