1
1
test_that(" config finding works" , {
2
2
run_quietly_in_a_dummy_golem({
3
+ # I. Testing behavior of the helper function - first case:
4
+ # file lives in default path and no envir-variable
3
5
config <- guess_where_config(
4
6
path = " ."
5
7
)
6
8
expect_exists(
7
9
config
8
10
)
9
- config <- try_user_config_location(
10
- pth = " ."
11
+ # II. Testing behavior of the helper function - second case:
12
+ # file lives in default path, and envir-variable set correctly
13
+ Sys.setenv(" GOLEM_CONFIG_PATH" = " ./inst/golem-config.yml" )
14
+ config <- guess_where_config(
15
+ path = " ."
11
16
)
12
17
expect_exists(
13
18
config
14
19
)
15
- expect_null(
16
- try_user_config_location(tempdir())
20
+ # III. Testing behavior of the helper function - third case:
21
+ # file lives in default path, and envir-variable set incorrectly
22
+ Sys.setenv(" GOLEM_CONFIG_PATH" = " ./inst/golem-config2.yml" )
23
+ testthat :: expect_error(
24
+ config <- guess_where_config(
25
+ path = " ."
26
+ ),
27
+ regexp = " Unable to locate a config file using the environment variable"
17
28
)
18
-
19
- config <- get_current_config(
20
- path = " ."
29
+ Sys.setenv(" GOLEM_CONFIG_PATH" = " " )
30
+ # IV. Testing behavior of the helper function - fourth case:
31
+ # file lives in another path, and hard coded path is wrongly passed
32
+ file.copy(from = " ./inst/golem-config.yml" ,
33
+ to = " ./inst/golem-config3.yml" )
34
+ file.remove(" ./inst/golem-config.yml" )
35
+ testthat :: expect_error(
36
+ config <- guess_where_config(
37
+ path = " ." ,
38
+ file = " inst/golem-config2.yml"
39
+ ),
40
+ regexp = " Unable to locate a config file from either the 'path' and 'file'"
21
41
)
22
-
42
+ # V. Testing behavior of the helper function:
43
+ # file lives in another path, and envir-var or path to file is wrong
44
+ Sys.setenv(" GOLEM_CONFIG_PATHHHHH" = " ./inst/golem-config2.yml" )
45
+ testthat :: expect_error(
46
+ config <- guess_where_config(
47
+ path = " ." ,
48
+ file = " inst/golem-config2.yml"
49
+ ),
50
+ regexp = " Unable to locate a config file from either the 'path' and 'file'"
51
+ )
52
+ file.copy(from = " ./inst/golem-config3.yml" ,
53
+ to = " ./inst/golem-config.yml" )
54
+ file.remove(" ./inst/golem-config3.yml" )
23
55
expect_exists(
24
56
config
25
57
)
26
-
27
58
unlink(
28
59
" R/app_config.R" ,
29
60
force = TRUE
@@ -52,9 +83,6 @@ test_that("config finding works", {
52
83
}
53
84
)
54
85
testthat :: with_mocked_bindings(
55
- guess_where_config = function (... ) {
56
- return (NULL )
57
- },
58
86
fs_file_exists = function (... ) {
59
87
return (FALSE )
60
88
},
@@ -71,27 +99,56 @@ test_that("config finding works", {
71
99
)
72
100
}
73
101
)
102
+ testthat :: with_mocked_bindings(
103
+ fs_file_exists = function (... ) {
104
+ return (FALSE )
105
+ },
106
+ rlang_is_interactive = function (... ) {
107
+ return (TRUE )
108
+ },
109
+ ask_golem_creation_upon_config = function (... ) {
110
+ return (FALSE )
111
+ },
112
+ {
113
+ config <- get_current_config()
114
+ expect_equal(config , NULL )
115
+ }
116
+ )
117
+ testthat :: with_mocked_bindings(
118
+ fs_file_exists = function (... ) {
119
+ return (FALSE )
120
+ },
121
+ rlang_is_interactive = function (... ) {
122
+ return (FALSE )
123
+ },
124
+ ask_golem_creation_upon_config = function (... ) {
125
+ return (FALSE )
126
+ },
127
+ {
128
+ expect_error(get_current_config())
129
+ }
130
+ )
74
131
})
75
132
76
133
77
- testthat :: with_mocked_bindings(
78
- fs_file_exists = function (... ) {
79
- return (FALSE )
80
- },
81
- rlang_is_interactive = function (... ) {
82
- return (TRUE )
83
- },
84
- ask_golem_creation_upon_config = function (... ) {
85
- return (FALSE )
86
- },
87
- {
88
- config <- get_current_config()
89
-
90
- expect_null(
91
- config
92
- )
93
- }
94
- )
134
+ # testthat::with_mocked_bindings(
135
+ # fs_file_exists = function(...) {
136
+ # return(FALSE)
137
+ # },
138
+ # rlang_is_interactive = function(...) {
139
+ # return(TRUE)
140
+ # },
141
+ # ask_golem_creation_upon_config = function(...) {
142
+ # return(FALSE)
143
+ # },
144
+ # {
145
+ # config <- get_current_config()
146
+ #
147
+ # expect_null(
148
+ # config
149
+ # )
150
+ # }
151
+ # )
95
152
})
96
153
97
154
test_that(" ask_golem_creation_upon_config works" , {
0 commit comments