Skip to content

Commit 5132e4e

Browse files
committed
uplink-sys(test): Run integration tests in storj-up environment
Previously the `uplink-sys` integration tests had to use a Storj network running somewhere or a external local environment that people had to set it up manually. The `uplink` crate was already using `storj-up` for its integration tests. This commit generalize the `storj-up` configuration used in the `uplink` crate to make available to both crates and adapt the `uplink-sys` Makefile, CI (Github workflow), and integration tests to use the `storj-up` environment. The changes make in the `uplink-sys` integration tests are only for making easier to adapt it to `storj-up` environment despite, now, it uses another function to get the access grant, the integration test was not exactly testing the previous function, so it has not changed the end goal of it. There is a minimal change in the CI (Github workflow) of the `uplink` crate that is out of the scope of this commit, but the changes are minimal and shouldn't confuse the reviewers. The changes are for adding a new step to the `check-implementation` job to simulate publishing the crate in order to verify that any merged PR shouldn't break its version publishing.
1 parent 90b12eb commit 5132e4e

File tree

11 files changed

+61
-69
lines changed

11 files changed

+61
-69
lines changed

.github/workflows/uplink-sys.yml

+1-10
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,14 @@ jobs:
2727
run: git submodule update --init
2828
- name: Lint
2929
run: make lint
30-
# Clippy
31-
#- name: clippy
32-
# workaround for clippy bug where it emits warnings instead of errors if it's not a clean build (or in this case we just fudge the timestamps of .rs files)
33-
#run: find . | grep "\.rs$" | xargs touch ; cargo clippy --workspace -- -D clippy::all
3430
- name: Build
3531
run: make build
3632
- name: Check lib binaries for docs.rs
3733
run: | # The way how to check if the libs are have to date with only comparing libuplink.pc isn't ideal but it's what we have found that works.
3834
make update-libs-docs-rs
3935
test -z $(git ls-files -d -m -o .docs-rs/libuplink.pc) || (printf "the uplink-c library binaries for docs.rs aren't up to date. Update them with `make update-libs-docs-rs`\n" && exit 1)
4036
git clean -fd && git checkout .
41-
- name: Create secrets for tests
42-
run: printf "${{ secrets.STORJ_TEST_SAT_ADDRESS }}\n${{ secrets.STORJ_TEST_API_KEY }}\n${{ secrets.STORJ_TEST_PASSPHRASE }}" > test_secrets.txt
4337
- name: Test
4438
run: make test
45-
- name: Delete secrets for tests
46-
if: always()
47-
run: rm -f test_secrets.txt
48-
- name: Crate Publish Test
39+
- name: Publish crate simulation
4940
run: make publish-test

.github/workflows/uplink.yml

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
- name: Clean up
3333
if: always()
3434
run: make clean
35+
- name: Publish crate simulation
36+
run: make publish-test
3537
test-implementation:
3638
runs-on: ubuntu-latest
3739
defaults:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
Cargo.lock
3+
.tmp/

Makefile

+33-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,38 @@ test:
2020
$(MAKE) -C uplink test
2121

2222
.PHONY: clean
23-
clean:
23+
clean: integration-tests-env-down
24+
rm -rf .tmp
2425
$(MAKE) -C uplink-sys clean
2526
$(MAKE) -C uplink clean
27+
28+
29+
.PHONY: integration-tests-env-up
30+
integration-tests-env-up:
31+
docker compose up -d
32+
$(MAKE) .tmp/env
33+
34+
.PHONY: integration-tests-env-down
35+
integration-tests-env-down:
36+
docker compose down
37+
rm -rf .tmp
38+
39+
.tmp/env: .tmp/up/storj-up
40+
@.tmp/up/storj-up credentials -e | grep -Ei "^export .+" > .tmp/env
41+
# TODO: This is a hack to get the AWS_* and STORJ_GATEWAY variables without
42+
# overriding the access grants because those variable are only available using
43+
# the storj-up from inside of the container, however, we cannot use the access
44+
# grants because they use the docker compose service name in the URL rather
45+
# than localhost and then it doesn't resolve.
46+
# See: https://github.com/storj/up/issues/45#issuecomment-1288808260
47+
@docker compose exec -T satellite-api storj-up credentials --s3 -e \
48+
-a http://authservice:8888 -s satellite-api \
49+
| grep -E 'AWS|STORJ_GATEWAY' >> .tmp/env
50+
51+
.tmp/up/storj-up: .tmp/up
52+
cd .tmp/up; go build -o storj-up
53+
54+
.tmp/up:
55+
mkdir -p .tmp
56+
cd .tmp; git clone https://github.com/storj/up.git
57+
cd .tmp/up; git checkout v1.1.0

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ Storj Uplink Rust bindings for the Rust programming language.
99

1010
## Repository layout
1111

12-
Following the conventions used for creating Rust bindings through [bindgen][bindgen], this repository contains two crates:
12+
Following the conventions used for creating Rust bindings through [bindgen][bindgen], this
13+
repository contains two crates:
1314

1415
* The [`uplink-sys`](uplink-sys) which is the unsafe Rust bindings auto-generated by [bindgen][bindgen].
1516
* The [`uplink`](uplink) which is the safe and idiomatic Rust binding build on top of the `uplink-sys`.
1617

1718
[bindgen]: https://github.com/rust-lang/rust-bindgen/
1819

19-
Each crate matches a root's child directory with the same name and each directory has its own README which provides more detailed information and its current status.
20+
Each crate matches a root's child directory with the same name and each directory has its own README
21+
which provides more detailed information and its current status.
22+
23+
The root directory of this repository, apart of Cargo files for defining a workspace and this
24+
README, it contains a _Makefile_ with targets to execute operations in both crates and operations that
25+
are shared between both crates.
26+
27+
The _docker-compose.yaml_ file is for executing all the external services that the integration tests
28+
requires.
File renamed without changes.

uplink-sys/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/target
22
Cargo.lock
3-
test_secrets.txt

uplink-sys/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LOCAL_ABS_CRATE_PATH := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
66
# Makefile special variables #
77

88
.DEFAULT_GOAL := build
9+
SHELL := /bin/bash
910

1011
# Targets #
1112

@@ -20,7 +21,8 @@ lint:
2021

2122
.PHONY: test
2223
test: $(UPLINK_C)/.git
23-
cargo test
24+
$(MAKE) -C .. integration-tests-env-up
25+
source ../.tmp/env; cargo test
2426

2527
.PHONY: publish-test
2628
publish-test: clean $(UPLINK_C)/.git

uplink-sys/tests/list_buckets.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1+
use std::env;
12
use std::ffi::{CStr, CString};
23
use std::fs;
34

45
#[test]
56
fn list_buckets() {
6-
// Get secrets for accessing project
7-
let secrets = fs::read_to_string("test_secrets.txt").unwrap();
8-
let secrets = secrets.lines().collect::<Vec<&str>>();
9-
assert_eq!(
10-
secrets.len(),
11-
3,
12-
"test_secrets.txt file has to contain 3 lines, satellite address, API key, and passphrase"
13-
);
14-
15-
// Access parameters
16-
let satellite_address = CString::new(secrets[0]).expect("CString::new failed");
17-
let api_key = CString::new(secrets[1]).expect("CString::new failed");
18-
let passphrase = CString::new(secrets[2]).expect("CString::new failed");
7+
let access_grant = env::var("STORJ_ACCESS").expect("STORJ_ACCESS env var isn't defined");
8+
let access_grant = CString::new(access_grant).expect("CString::new failed");
199

2010
unsafe {
21-
// Request access
22-
let access_result = uplink_sys::uplink_request_access_with_passphrase(
23-
satellite_address.as_ptr() as *mut uplink_sys::uplink_const_char,
24-
api_key.as_ptr() as *mut uplink_sys::uplink_const_char,
25-
passphrase.as_ptr() as *mut uplink_sys::uplink_const_char,
11+
// Parse access grant
12+
let access_result = uplink_sys::uplink_parse_access(
13+
access_grant.as_ptr() as *mut uplink_sys::uplink_const_char
2614
);
2715

2816
assert_eq!(access_result.error, std::ptr::null_mut()); // verify no error

uplink/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/target
22
Cargo.lock
3-
tests/.tmp/

uplink/Makefile

+4-35
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,18 @@ test-doc:
2323
cargo test --doc
2424

2525
.PHONY: test-integration
26-
test-integration: integration-tests-env-up tests/.tmp/env
26+
test-integration:
27+
$(MAKE) -C .. integration-tests-env-up
2728
# We don't use `cargo test --test` because it requires to pass a specific test file name and
2829
# it doesn't accept a list of files. For being able to only run the integration tests we prefix
2930
# all the integration tests functions with `integration_` and then filter them with the usual
3031
# `cargo test` command.
31-
source tests/.tmp/env; cargo test integration
32+
source ../.tmp/env; cargo test integration
3233

3334
.PHONY: test-unit
3435
test-unit:
3536
cargo test --lib
3637

37-
tests/.tmp/env: tests/.tmp/up/storj-up
38-
$(MAKE) integration-tests-credentials | grep -Ei "^export .+" > tests/.tmp/env
39-
# TODO(github.com/storj-thirdparty/uplink-rust/issues/48): This is a hack to get the AWS_* and
40-
# STORJ_GATEWAY variables without overriding the access grants because those variable are only
41-
# available using the storj-up from inside of the container, however, we cannot use the access
42-
# grants because they use the docker compose service name in the URL rather than localhost and
43-
# then it doesn't resolve.
44-
@cd tests; docker compose exec -T satellite-api storj-up credentials --s3 -e \
45-
-a http://authservice:8888 -s satellite-api \
46-
| grep -E 'AWS|STORJ_GATEWAY' >> .tmp/env
47-
48-
.PHONY: integration-tests-credentials
49-
integration-tests-credentials: tests/.tmp/up/storj-up
50-
@cd tests; .tmp/up/storj-up credentials -e
51-
52-
.PHONY: integration-tests-env-up
53-
integration-tests-env-up:
54-
cd tests; docker compose up -d
55-
56-
.PHONY: .integration-tests-env-down
57-
.integration-tests-env-down:
58-
cd tests; docker compose down
59-
60-
tests/.tmp/up/storj-up: tests/.tmp/up
61-
cd tests/.tmp/up; go build -o storj-up
62-
63-
tests/.tmp/up:
64-
mkdir -p tests/.tmp
65-
cd tests/.tmp; git clone https://github.com/storj/up.git
66-
cd tests/.tmp/up; git checkout v1.1.0
67-
6838
## Publish crate ##
6939
.PHONY: publish-test
7040
publish-test:
@@ -76,6 +46,5 @@ _publish-crate:
7646

7747
## Clean ##
7848
.PHONY: clean
79-
clean: .integration-tests-env-down
80-
rm -rf tests/.tmp
49+
clean:
8150
cargo clean

0 commit comments

Comments
 (0)