1
- test_that(" config finding works" , {
1
+ test_that(" guess_where_config works" , {
2
+ # Default behavior, default structure
2
3
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
5
4
config <- guess_where_config(
6
5
path = " ."
7
6
)
8
7
expect_exists(
9
8
config
10
9
)
11
- # II. Testing behavior of the helper function - second case:
12
- # file lives in default path, and envir-variable set correctly
10
+ })
11
+ # Default behavior, default structure
12
+ run_quietly_in_a_dummy_golem({
13
+ unlink(" ./inst/golem-config.yml" )
14
+ expect_error({
15
+ guess_where_config(
16
+ path = " ."
17
+ )
18
+ })
19
+ })
13
20
21
+ # Using the envvar, case one with a file that exists
22
+ run_quietly_in_a_dummy_golem({
23
+ fs_file_copy(
24
+ " ./inst/golem-config.yml" ,
25
+ " ./inst/golem-config2.yml"
26
+ )
14
27
withr :: with_envvar(
15
- c(" GOLEM_CONFIG_PATH" = " ./inst/golem-config .yml" ),
28
+ c(" GOLEM_CONFIG_PATH" = " ./inst/golem-config2 .yml" ),
16
29
{
17
30
config <- guess_where_config(
18
31
path = " ."
@@ -22,146 +35,63 @@ test_that("config finding works", {
22
35
)
23
36
}
24
37
)
38
+ })
25
39
26
- # III. Testing behavior of the helper function - third case:
27
- # file lives in default path, and envir-variable set incorrectly
40
+ # Using the envvar, case one with a file that exists
41
+ run_quietly_in_a_dummy_golem({
28
42
withr :: with_envvar(
29
43
c(" GOLEM_CONFIG_PATH" = " ./inst/golem-config2.yml" ),
30
44
{
31
- testthat :: expect_error(
45
+ expect_error(
32
46
guess_where_config(
33
47
path = " ."
34
- ),
35
- regexp = " but we were unable to locate"
48
+ )
36
49
)
37
50
}
38
51
)
52
+ })
53
+ })
39
54
40
- # IV. Testing behavior of the helper function - fourth case:
41
- # file lives in another path, and hard coded path is wrongly passed
42
- file.copy(
43
- from = " ./inst/golem-config.yml" ,
44
- to = " ./inst/golem-config3.yml"
45
- )
46
- file.remove(" ./inst/golem-config.yml" )
47
- testthat :: expect_error(
48
- guess_where_config(
49
- path = " ." ,
50
- file = " inst/golem-config2.yml"
51
- ),
52
- regexp = " Unable to locate a config file"
53
- )
54
- # V. Testing behavior of the helper function:
55
- # file lives in another path, and envir-var or path to file is wrong
56
- Sys.setenv(" GOLEM_CONFIG_PATHHHHH" = " ./inst/golem-config2.yml" )
57
- testthat :: expect_error(
58
- guess_where_config(
59
- path = " ." ,
60
- file = " inst/golem-config2.yml"
61
- ),
62
- regexp = " Unable to locate a config file"
63
- )
64
- file.copy(
65
- from = " ./inst/golem-config3.yml" ,
66
- to = " ./inst/golem-config.yml"
67
- )
68
- file.remove(" ./inst/golem-config3.yml" )
69
- expect_exists(
70
- config
71
- )
72
- unlink(
73
- " R/app_config.R" ,
74
- force = TRUE
75
- )
76
- unlink(
77
- " inst/golem-config.yml" ,
78
- force = TRUE
79
- )
55
+ test_that(" get_current_config works" , {
56
+ run_quietly_in_a_dummy_golem({
57
+ # We don't need to retest guess_where_config
80
58
testthat :: with_mocked_bindings(
81
- guess_where_config = function (... ) {
82
- return (NULL )
83
- },
84
- rlang_is_interactive = function (... ) {
59
+ fs_file_exists = function (... ) {
85
60
return (FALSE )
86
61
},
87
62
{
88
- expect_error(
89
- get_current_config()
90
- )
91
- expect_false(
92
- file.exists(" R/app_config.R" )
93
- )
94
- expect_false(
95
- file.exists(" inst/golem-config.yml" )
96
- )
63
+ expect_error(get_current_config())
97
64
}
98
65
)
66
+ })
67
+ run_quietly_in_a_dummy_golem({
68
+ # We don't need to retest guess_where_config
99
69
testthat :: with_mocked_bindings(
100
70
fs_file_exists = function (... ) {
101
71
return (FALSE )
102
72
},
73
+ guess_where_config = function (... ) {
74
+ return (" " )
75
+ },
103
76
rlang_is_interactive = function (... ) {
104
77
return (TRUE )
105
78
},
106
79
ask_golem_creation_upon_config = function (... ) {
107
80
return (TRUE )
108
81
},
109
82
{
110
- config <- get_current_config()
83
+ unlink(" inst/golem-config.yml" )
84
+ unlink(" R/app_config.R" )
85
+ get_current_config()
111
86
expect_exists(
112
- config
87
+ " inst/golem-config.yml"
88
+ )
89
+ expect_exists(
90
+ " R/app_config.R"
113
91
)
114
- }
115
- )
116
- testthat :: with_mocked_bindings(
117
- fs_file_exists = function (... ) {
118
- return (FALSE )
119
- },
120
- rlang_is_interactive = function (... ) {
121
- return (TRUE )
122
- },
123
- ask_golem_creation_upon_config = function (... ) {
124
- return (FALSE )
125
- },
126
- {
127
- config <- get_current_config()
128
- expect_equal(config , NULL )
129
- }
130
- )
131
- testthat :: with_mocked_bindings(
132
- fs_file_exists = function (... ) {
133
- return (FALSE )
134
- },
135
- rlang_is_interactive = function (... ) {
136
- return (FALSE )
137
- },
138
- ask_golem_creation_upon_config = function (... ) {
139
- return (FALSE )
140
- },
141
- {
142
- expect_error(get_current_config())
143
92
}
144
93
)
145
94
})
146
-
147
- # testthat::with_mocked_bindings(
148
- # fs_file_exists = function(...) {
149
- # return(FALSE)
150
- # },
151
- # rlang_is_interactive = function(...) {
152
- # return(TRUE)
153
- # },
154
- # ask_golem_creation_upon_config = function(...) {
155
- # return(FALSE)
156
- # },
157
- # {
158
- # config <- get_current_config()
159
- #
160
- # expect_null(
161
- # config
162
- # )
163
- # }
164
- # )
165
95
})
166
96
167
97
test_that(" ask_golem_creation_upon_config works" , {
0 commit comments