Skip to content

Commit c8030f5

Browse files
committed
Fix tests on macOS
At least locally, let's see the CI.
1 parent 1db92d3 commit c8030f5

File tree

7 files changed

+61
-19
lines changed

7 files changed

+61
-19
lines changed

tests/testthat/_snaps/cache.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# gitcreds_cache_envvvar [osxkeychain]
2+
3+
Code
4+
gitcreds_cache_envvar("foo.bar")
5+
Condition
6+
Error in `gitcreds_cache_envvar()`:
7+
! Invalid URL(s): foo.bar
8+
9+
# gitcreds_cache_envvvar [manager-core]
10+
11+
Code
12+
gitcreds_cache_envvar("foo.bar")
13+
Condition
14+
Error in `gitcreds_cache_envvar()`:
15+
! Invalid URL(s): foo.bar
16+

tests/testthat/_snaps/username.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# errors [osxkeychain]
2+
3+
Code
4+
gitcreds$gitcreds_username_for_url("https://github.com")
5+
Condition
6+
Error in `new_git_error()`:
7+
! System git failed:
8+
Code
9+
gitcreds$gitcreds_username_generic()
10+
Condition
11+
Error in `new_git_error()`:
12+
! System git failed:
13+
14+
# errors [manager-core]
15+
16+
Code
17+
gitcreds$gitcreds_username_for_url("https://github.com")
18+
Condition
19+
Error in `new_git_error()`:
20+
! System git failed:
21+
Code
22+
gitcreds$gitcreds_username_generic()
23+
Condition
24+
Error in `new_git_error()`:
25+
! System git failed:
26+

tests/testthat/helper.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ gc_test_that_run <- function(desc, code) {
5858

5959
envnames <- grep("^GITHUB_PAT", names(Sys.getenv()), value = TRUE)
6060
envs <- structure(rep(NA_character_, length(envnames)), names = envnames)
61+
tmpconfig <- tempfile()
62+
on.exit(unlink(tmpconfig), add = TRUE)
6163
withr::local_envvar(c(
6264
envs,
6365
GCM_AUTHORITY = NA_character_,
64-
GCM_PROVIDER = NA_character_
66+
GCM_PROVIDER = NA_character_,
67+
GIT_CONFIG_GLOBAL = tmpconfig
6568
))
6669

6770
test_that(desc, {

tests/testthat/setup.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tempconfig <- tempfile()
2+
withr::local_envvar(
3+
GIT_CONFIG_GLOBAL = tempconfig,
4+
.local_envir = teardown_env()
5+
)
6+
withr::defer(unlink(tempconfig), envir = teardown_env())

tests/testthat/test-cache.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ gc_test_that("gitcreds_cache_envvvar", {
1818
)
1919

2020
# error
21-
expect_error(gitcreds_cache_envvar("foo.bar"), "Invalid URL")
21+
expect_snapshot(error = TRUE, gitcreds_cache_envvar("foo.bar"))
2222
})
2323

2424
gc_test_that("gitcreds_get_cache", {

tests/testthat/test-gitcreds-list.R

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ gc_test_that(
143143

144144
lst <- gitcreds_list()
145145
expect_equal(length(lst), 1L)
146-
expect_equal(lst[[1]]$attributes$service, "git:https://github.com")
146+
expect_equal(lst[[1]]$attributes$label, "github.com")
147147

148148
lst2 <- gitcreds_list(url = NULL)
149149
expect_true(length(lst2) == 1)
150-
expect_equal(lst2[[1]]$attributes$service, "git:https://github.com")
150+
expect_equal(lst2[[1]]$attributes$label, "github.com")
151151

152152
cred2 <- list(
153153
url = "https://github2.com",
@@ -158,22 +158,11 @@ gc_test_that(
158158

159159
lst3 <- gitcreds_list()
160160
expect_equal(length(lst3), 1L)
161-
expect_equal(lst3[[1]]$attributes$service, "git:https://github.com")
161+
expect_equal(lst3[[1]]$attributes$label, "github.com")
162162

163163
lst4 <- gitcreds_list("https://github2.com")
164164
expect_equal(length(lst4), 1L)
165-
expect_equal(lst4[[1]]$attributes$service, "git:https://github2.com")
166-
167-
lst5 <- gitcreds_list(url = NULL)
168-
expect_true(length(lst5) >= 2)
169-
expect_true(
170-
"git:https://github.com" %in%
171-
vapply(lst5, function(it) it$attributes$service, "")
172-
)
173-
expect_true(
174-
"git:https://github2.com" %in%
175-
vapply(lst5, function(it) it$attributes$service, "")
176-
)
165+
expect_equal(lst4[[1]]$attributes$label, "github2.com")
177166
}
178167
)
179168

tests/testthat/test-username.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ gc_test_that("errors", {
4646
}
4747
mockery::stub(gitcreds$gitcreds_username_for_url, "git_run", mock2)
4848
mockery::stub(gitcreds$gitcreds_username_generic, "git_run", mock2)
49-
expect_error(gitcreds$gitcreds_username_for_url("https://github.com"))
50-
expect_error(gitcreds$gitcreds_username_generic())
49+
expect_snapshot(error = TRUE, {
50+
gitcreds$gitcreds_username_for_url("https://github.com")
51+
gitcreds$gitcreds_username_generic()
52+
})
5153
})

0 commit comments

Comments
 (0)