Skip to content

Commit e82659f

Browse files
refactor: remove prefix from connect() and just use the usual env vars (#477)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 830b6c3 commit e82659f

28 files changed

+286
-312
lines changed

.github/workflows/integration-tests.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,11 @@ jobs:
4747
shell: Rscript {0}
4848

4949
- name: Run integration tests
50-
uses: nealrichardson/with-connect
50+
uses: posit-dev/with-connect@main
5151
env:
5252
CONNECTAPI_INTEGRATED: "true"
5353
with:
5454
version: ${{ matrix.version }}
5555
license: ${{ secrets.CONNECT_LICENSE_FILE }}
56-
# TODO: rewrite tests to use CONNECT_* env vars directly
5756
command: |
58-
Rscript -e '
59-
Sys.setenv(
60-
TEST_1_SERVER=Sys.getenv("CONNECT_SERVER"),
61-
TEST_1_API_KEY=Sys.getenv("CONNECT_API_KEY")
62-
)
63-
source("tests/test-integrated.R")'
57+
Rscript -e 'source("tests/test-integrated.R")'

.github/workflows/pkgdown.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,12 @@ jobs:
3434
needs: website
3535

3636
- name: Build site
37-
uses: nealrichardson/with-connect
37+
uses: posit-dev/with-connect@main
3838
with:
3939
# Runs on the default version in the with-connect action
4040
license: ${{ secrets.CONNECT_LICENSE_FILE }}
41-
# TODO: rewrite tests to use CONNECT_* env vars directly
4241
command: |
43-
Rscript -e '
44-
Sys.setenv(
45-
TEST_1_SERVER=Sys.getenv("CONNECT_SERVER"),
46-
TEST_1_API_KEY=Sys.getenv("CONNECT_API_KEY")
47-
)
48-
pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)'
42+
Rscript -e 'pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)'
4943
5044
- name: Deploy to GitHub pages 🚀
5145
if: github.event_name != 'pull_request'

.github/workflows/test-coverage.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,19 @@ jobs:
2929
needs: coverage
3030

3131
- name: Run coverage
32-
uses: nealrichardson/with-connect
32+
uses: posit-dev/with-connect@main
3333
env:
3434
CONNECTAPI_INTEGRATED: "true"
3535
with:
3636
# Runs on the default version in the with-connect action
3737
license: ${{ secrets.CONNECT_LICENSE_FILE }}
38-
# TODO: rewrite tests to use CONNECT_* env vars directly
3938
command: |
4039
Rscript -e '
41-
Sys.setenv(
42-
TEST_1_SERVER=Sys.getenv("CONNECT_SERVER"),
43-
TEST_1_API_KEY=Sys.getenv("CONNECT_API_KEY")
44-
)
45-
token <- "${{ secrets.CODECOV_TOKEN }}"
4640
covr::codecov(
4741
quiet = FALSE,
4842
clean = FALSE,
4943
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package"),
50-
token = if (token != "") token
44+
token = "${{ secrets.CODECOV_TOKEN }}"
5145
)'
5246
5347

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# connectapi (development version)
22

3+
- Removed `prefix` argument to `connect()` function, which was a convenience utility for testing. (#477)
4+
35
# connectapi 0.9.0
46

57
- New `set_integrations()` function to set the OAuth integration

R/connect.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,6 @@ Connect <- R6::R6Class(
963963
#' `Connect` object using the `api_key`. By providing a different
964964
#' key here you can test a visitor client with differently-scoped
965965
#' permissions.
966-
#' @param prefix The prefix used to determine environment variables
967966
#' @param audience Optional. The GUID of a Connect API integration associated with this piece of content.
968967
#' @param ... Additional arguments. Not used at present
969968
#' @param .check_is_fatal Whether to fail if "check" requests fail. Useful in
@@ -991,21 +990,21 @@ Connect <- R6::R6Class(
991990
#' @examplesIf identical(Sys.getenv("IN_PKGDOWN"), "true")
992991
#'
993992
#' # default is to read CONNECT_SERVER and CONNECT_API_KEY environment variables
994-
#' # this example will read TEST_1_SERVER and TEST_1_API_KEY
995-
#' connect(prefix = "TEST_1")
993+
#' connect()
996994
#'
997995
#' @export
998996
connect <- function(
999-
server = Sys.getenv(paste0(prefix, "_SERVER"), NA_character_),
1000-
api_key = Sys.getenv(paste0(prefix, "_API_KEY"), NA_character_),
997+
server = Sys.getenv("CONNECT_SERVER"),
998+
api_key = Sys.getenv("CONNECT_API_KEY"),
1001999
token,
10021000
token_local_testing_key = api_key,
1003-
prefix = "CONNECT",
10041001
audience = NULL,
10051002
...,
10061003
.check_is_fatal = TRUE
10071004
) {
1008-
if (is.null(api_key) || is.na(api_key) || nchar(api_key) == 0) {
1005+
if (
1006+
missing(token) && is.null(api_key) || is.na(api_key) || nchar(api_key) == 0
1007+
) {
10091008
msg <- "Invalid (empty) API key. Please provide a valid API key"
10101009
if (.check_is_fatal) {
10111010
stop(glue::glue("ERROR: {msg}"))

R/deploy.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ download_bundle <- function(
402402
#' }
403403
#' @examplesIf identical(Sys.getenv("IN_PKGDOWN"), "true")
404404
#'
405-
#' client <- connect(prefix = "TEST_1")
405+
#' client <- connect()
406406
#' bnd <- bundle_path(system.file("tests/testthat/examples/static.tar.gz", package = "connectapi"))
407407
#' deploy(client, bnd)
408408
#'
@@ -413,8 +413,7 @@ deploy <- function(
413413
title = name,
414414
guid = NULL,
415415
...,
416-
.pre_deploy = {
417-
}
416+
.pre_deploy = {}
418417
) {
419418
validate_R6_class(bundle, "Bundle")
420419
validate_R6_class(connect, "Connect")

man/connect.Rd

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/deploy.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrated/setup.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test_conn_1 <- connect(prefix = "TEST_1")
1+
client <- connect()

tests/integrated/test-connect.R

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,12 @@
1-
test_that("connect works", {
2-
conn <- connect(
3-
server = Sys.getenv("TEST_1_SERVER"),
4-
api_key = Sys.getenv("TEST_1_API_KEY")
5-
)
6-
expect_true(validate_R6_class(conn, "Connect"))
7-
})
8-
9-
test_that("connect works with prefix only", {
10-
conn <- connect(prefix = "TEST_1")
11-
expect_true(validate_R6_class(conn, "Connect"))
12-
})
13-
14-
test_that("connect fails for nonexistent server", {
15-
expect_error({
16-
connect(server = "does-not-exist.rstudio.com", api_key = "bogus")
17-
})
1+
# This whole suite assumes CONNECT_SERVER and CONNECT_API_KEY env vars are set
2+
test_that("connect() works", {
3+
expect_true(validate_R6_class(connect(), "Connect"))
184
})
195

206
test_that("connect fails for good server, bad api key", {
217
expect_error({
228
connect(
23-
server = Sys.getenv("TEST_1_SERVER"),
249
api_key = "bogus"
2510
)
2611
})
2712
})
28-
29-
test_that("error if API key is empty", {
30-
expect_error(
31-
connect(server = Sys.getenv("TEST_1_SERVER"), api_key = ""),
32-
"provide a valid API key"
33-
)
34-
35-
expect_error(
36-
connect(server = Sys.getenv("TEST_1_SERVER"), api_key = NA_character_),
37-
"provide a valid API key"
38-
)
39-
40-
expect_error(
41-
connect(server = Sys.getenv("TEST_1_SERVER"), api_key = NULL),
42-
"provide a valid API key"
43-
)
44-
})
45-
46-
test_that(".check_is_fatal toggle works", {
47-
expect_error(
48-
connect(server = Sys.getenv("TEST_1_SERVER"), api_key = ""),
49-
"provide a valid API key"
50-
)
51-
52-
rsc <- connect(
53-
server = Sys.getenv("TEST_1_SERVER"),
54-
api_key = "",
55-
.check_is_fatal = FALSE
56-
)
57-
expect_true(
58-
validate_R6_class(rsc, "Connect")
59-
)
60-
61-
expect_error(
62-
suppressMessages(connect(
63-
server = "http://fake-value.example.com",
64-
api_key = "fake-value"
65-
)),
66-
"Could not resolve host"
67-
)
68-
69-
# TODO: suppressing the message in the tryCatch handler does not work...?
70-
rsc1 <- suppressMessages(connect(
71-
server = "http://fake-value.example.com",
72-
api_key = "fake-value",
73-
.check_is_fatal = FALSE
74-
))
75-
expect_true(
76-
validate_R6_class(rsc1, "Connect")
77-
)
78-
})

0 commit comments

Comments
 (0)