Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,11 @@ jobs:
shell: Rscript {0}

- name: Run integration tests
uses: nealrichardson/with-connect@dev
uses: posit-dev/with-connect@main
env:
CONNECTAPI_INTEGRATED: "true"
with:
version: ${{ matrix.version }}
license: ${{ secrets.CONNECT_LICENSE_FILE }}
# TODO: rewrite tests to use CONNECT_* env vars directly
command: |
Rscript -e '
Sys.setenv(
TEST_1_SERVER=Sys.getenv("CONNECT_SERVER"),
TEST_1_API_KEY=Sys.getenv("CONNECT_API_KEY")
)
source("tests/test-integrated.R")'
Rscript -e 'source("tests/test-integrated.R")'
10 changes: 2 additions & 8 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,12 @@ jobs:
needs: website

- name: Build site
uses: nealrichardson/with-connect@dev
uses: posit-dev/with-connect@main
with:
# Runs on the default version in the with-connect action
license: ${{ secrets.CONNECT_LICENSE_FILE }}
# TODO: rewrite tests to use CONNECT_* env vars directly
command: |
Rscript -e '
Sys.setenv(
TEST_1_SERVER=Sys.getenv("CONNECT_SERVER"),
TEST_1_API_KEY=Sys.getenv("CONNECT_API_KEY")
)
pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)'
Rscript -e 'pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)'

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,19 @@ jobs:
needs: coverage

- name: Run coverage
uses: nealrichardson/with-connect@dev
uses: posit-dev/with-connect@main
env:
CONNECTAPI_INTEGRATED: "true"
with:
# Runs on the default version in the with-connect action
license: ${{ secrets.CONNECT_LICENSE_FILE }}
# TODO: rewrite tests to use CONNECT_* env vars directly
command: |
Rscript -e '
Sys.setenv(
TEST_1_SERVER=Sys.getenv("CONNECT_SERVER"),
TEST_1_API_KEY=Sys.getenv("CONNECT_API_KEY")
)
token <- "${{ secrets.CODECOV_TOKEN }}"
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package"),
token = if (token != "") token
token = "${{ secrets.CODECOV_TOKEN }}"
)'


Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- New `lock_content()` and `unlock_content()` functions for locking and unlocking
content items. (#453)
- Updated git-backed deployment functions to use v1 APIs (#459)
- Removed `prefix` argument to `connect()` function, which was a convenience utility for testing. (#477)

# connectapi 0.8.0

Expand Down
13 changes: 6 additions & 7 deletions R/connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,6 @@ Connect <- R6::R6Class(
#' `Connect` object using the `api_key`. By providing a different
#' key here you can test a visitor client with differently-scoped
#' permissions.
#' @param prefix The prefix used to determine environment variables
#' @param audience Optional. The GUID of a Connect API integration associated with this piece of content.
#' @param ... Additional arguments. Not used at present
#' @param .check_is_fatal Whether to fail if "check" requests fail. Useful in
Expand Down Expand Up @@ -991,21 +990,21 @@ Connect <- R6::R6Class(
#' @examplesIf identical(Sys.getenv("IN_PKGDOWN"), "true")
#'
#' # default is to read CONNECT_SERVER and CONNECT_API_KEY environment variables
#' # this example will read TEST_1_SERVER and TEST_1_API_KEY
#' connect(prefix = "TEST_1")
#' connect()
#'
#' @export
connect <- function(
server = Sys.getenv(paste0(prefix, "_SERVER"), NA_character_),
api_key = Sys.getenv(paste0(prefix, "_API_KEY"), NA_character_),
server = Sys.getenv("CONNECT_SERVER"),
api_key = Sys.getenv("CONNECT_API_KEY"),
token,
token_local_testing_key = api_key,
prefix = "CONNECT",
audience = NULL,
...,
.check_is_fatal = TRUE
) {
if (is.null(api_key) || is.na(api_key) || nchar(api_key) == 0) {
if (
missing(token) && is.null(api_key) || is.na(api_key) || nchar(api_key) == 0
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this missing(token) bit because it seemed odd that we would validate the API key if instead we were going to use the token. Seemed like we were relying on the fact that there happens to be a CONNECT_API_KEY set on Connect always. But maybe I misunderstood: do you need an API key in order to exchange the token?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm — I think this is the case, I think you need the API key to exchange the token (see that a client is created on line 1015).

However, token exchange only ever happens on Connect and we always have the CONNECT_SERVER environment variable there, so… I think this is a moot point and probably fine.

) {
msg <- "Invalid (empty) API key. Please provide a valid API key"
if (.check_is_fatal) {
stop(glue::glue("ERROR: {msg}"))
Expand Down
5 changes: 2 additions & 3 deletions R/deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ download_bundle <- function(
#' }
#' @examplesIf identical(Sys.getenv("IN_PKGDOWN"), "true")
#'
#' client <- connect(prefix = "TEST_1")
#' client <- connect()
#' bnd <- bundle_path(system.file("tests/testthat/examples/static.tar.gz", package = "connectapi"))
#' deploy(client, bnd)
#'
Expand All @@ -413,8 +413,7 @@ deploy <- function(
title = name,
guid = NULL,
...,
.pre_deploy = {
}
.pre_deploy = {}
) {
validate_R6_class(bundle, "Bundle")
validate_R6_class(connect, "Connect")
Expand Down
10 changes: 3 additions & 7 deletions man/connect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/deploy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrated/setup.R
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test_conn_1 <- connect(prefix = "TEST_1")
client <- connect()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the opportunity to rename all of these in the integration tests to be client.

72 changes: 3 additions & 69 deletions tests/integrated/test-connect.R
Original file line number Diff line number Diff line change
@@ -1,78 +1,12 @@
test_that("connect works", {
conn <- connect(
server = Sys.getenv("TEST_1_SERVER"),
api_key = Sys.getenv("TEST_1_API_KEY")
)
expect_true(validate_R6_class(conn, "Connect"))
})

test_that("connect works with prefix only", {
conn <- connect(prefix = "TEST_1")
expect_true(validate_R6_class(conn, "Connect"))
})

test_that("connect fails for nonexistent server", {
expect_error({
connect(server = "does-not-exist.rstudio.com", api_key = "bogus")
})
# This whole suite assumes CONNECT_SERVER and CONNECT_API_KEY env vars are set
test_that("connect() works", {
expect_true(validate_R6_class(connect(), "Connect"))
})

test_that("connect fails for good server, bad api key", {
expect_error({
connect(
server = Sys.getenv("TEST_1_SERVER"),
api_key = "bogus"
)
})
})

test_that("error if API key is empty", {
expect_error(
connect(server = Sys.getenv("TEST_1_SERVER"), api_key = ""),
"provide a valid API key"
)

expect_error(
connect(server = Sys.getenv("TEST_1_SERVER"), api_key = NA_character_),
"provide a valid API key"
)

expect_error(
connect(server = Sys.getenv("TEST_1_SERVER"), api_key = NULL),
"provide a valid API key"
)
})

test_that(".check_is_fatal toggle works", {
expect_error(
connect(server = Sys.getenv("TEST_1_SERVER"), api_key = ""),
"provide a valid API key"
)

rsc <- connect(
server = Sys.getenv("TEST_1_SERVER"),
api_key = "",
.check_is_fatal = FALSE
)
expect_true(
validate_R6_class(rsc, "Connect")
)

expect_error(
suppressMessages(connect(
server = "http://fake-value.example.com",
api_key = "fake-value"
)),
"Could not resolve host"
)

# TODO: suppressing the message in the tryCatch handler does not work...?
rsc1 <- suppressMessages(connect(
server = "http://fake-value.example.com",
api_key = "fake-value",
.check_is_fatal = FALSE
))
expect_true(
validate_R6_class(rsc1, "Connect")
)
})
Loading
Loading