-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest_profile.R
More file actions
100 lines (84 loc) · 3.25 KB
/
Copy pathtest_profile.R
File metadata and controls
100 lines (84 loc) · 3.25 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
library(tinytest)
library(tiledb)
# Use base directory to prevent over-writing user profiles.
base_dir <- tempdir()
dir1 <- file.path(base_dir, "tiledb_profile")
# 1. Test creating profiles.
profile1 <- tiledb_profile()
profile2 <- tiledb_profile("profile2")
profile3 <- tiledb_profile(dir=dir1)
profile4 <- tiledb_profile("profile4", dir1)
expect_equal(tiledb_profile_name(profile1), "default")
expect_equal(tiledb_profile_name(profile2), "profile2")
expect_equal(tiledb_profile_name(profile3), "default")
expect_equal(tiledb_profile_name(profile4), "profile4")
# Skipping checks for default directory since it is platform dependent.
# Normalize paths on Windows to UNIX-style
expected_dir <- normalizePath(
path = dir1,
winslash = "/",
mustWork = FALSE
)
actual_dir_profile3 <- normalizePath(
path = tiledb_profile_dir(profile3),
winslash = "/",
mustWork = FALSE
)
expect_identical(
# trim trailing slashes
current = sub(pattern = "/+$", replacement = "", x = actual_dir_profile3),
target = expected_dir
)
actual_dir_profile4 <- normalizePath(
path = tiledb_profile_dir(profile4),
winslash = "/",
mustWork = FALSE
)
expect_identical(
current = sub(pattern = "/+$", replacement = "", x = actual_dir_profile4),
target = expected_dir
)
# 2. Test setting/getting profile parameters.
key1 <- "username"
key2 <- "server_address"
key3 <- "rest.token"
expected_value1 <- "my_username"
expected_value2 <- "https://my.address"
expected_value3 <- "123456"
tiledb_profile_set_param(profile4, key1, expected_value1)
tiledb_profile_set_param(profile4, key2, expected_value2)
tiledb_profile_set_param(profile4, key3, expected_value3)
actual_value1 <- tiledb_profile_get_param(profile4, key1)
actual_value2 <- tiledb_profile_get_param(profile4, key2)
actual_value3 <- tiledb_profile_get_param(profile4, key3)
actual_non_value <- tiledb_profile_get_param(profile4, "not_a_parameter")
expect_equal(actual_value1, expected_value1)
expect_equal(actual_value2, expected_value2)
expect_equal(actual_value3, expected_value3)
expect_true(is.null(actual_non_value))
# 3. Test save, load, and remove.
# IMPORTANT: Do not save a profile to a location that might over-write an actual profile.
tiledb_profile_save(profile3)
tiledb_profile_save(profile4)
# -- Check can load profile3
profile_loaded <- tiledb_profile_load(dir=dir1)
# -- Remove profile2. Check can no longer load.
tiledb_profile_remove(dir=dir1)
expect_error(tiledb_profile_load(dir=dir1))
# -- Check loaded profile4
profile_loaded <- tiledb_profile_load("profile4", dir1)
expect_equal(tiledb_profile_name(profile_loaded), "profile4")
expect_equal(tiledb_profile_name(profile_loaded), "profile4")
loaded_value1 <- tiledb_profile_get_param(profile_loaded, key1)
loaded_value2 <- tiledb_profile_get_param(profile_loaded, key2)
loaded_value3 <- tiledb_profile_get_param(profile_loaded, key3)
loaded_non_value <- tiledb_profile_get_param(profile_loaded, "not_a_parameter")
expect_equal(loaded_value1, expected_value1)
expect_equal(loaded_value2, expected_value2)
expect_equal(loaded_value3, expected_value3)
expect_true(is.null(loaded_non_value))
# -- Remove profile4
tiledb_profile_remove("profile4", dir1)
# -- Check cannot load profile2 or profile4.
expect_error(tiledb_profile_load(dir=dir1))
expect_error(tiledb_profile_load("profile4", dir1))