Skip to content
This repository was archived by the owner on Jul 6, 2024. It is now read-only.

Commit ad71f48

Browse files
committed
tests: Integrate go-proton-api server for unit tests
Test unit tests against https://github.com/ProtonMail/go-proton-api via a custom C interface.
1 parent 991b749 commit ad71f48

File tree

18 files changed

+662
-7
lines changed

18 files changed

+662
-7
lines changed

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ optional = true
4141
env_logger = "0.10"
4242
tokio = {version ="1", features = ["full"]}
4343
httpmock = "0.6"
44+
go-gpa-server = {path= "go-gpa-server"}
4445

4546
[[example]]
4647
name = "user_id"
@@ -49,3 +50,8 @@ required-features = ["http-reqwest"]
4950
[[example]]
5051
name = "user_id_sync"
5152
required-features = ["http-ureq"]
53+
54+
[[test]]
55+
name = "session"
56+
required-features = ["http-ureq"]
57+

go-gpa-server/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
Cargo.lock

go-gpa-server/Cargo.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "go-gpa-server"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["Leander Beernaert <[email protected]>"]
6+
license = "AGPL-3.0-only"
7+
description = "API test server from https://github.com/ProtonMail/go-proton-api"
8+
keywords = ["api"]
9+
categories = ["api-bindings"]
10+
publish = false
11+
12+
[dependencies]
13+
base64 = "0.21"
14+
15+
[build-dependencies]
16+
bindgen = "0.64"

go-gpa-server/build.rs

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use bindgen::EnumVariation;
2+
use std::env;
3+
use std::io::{stderr, Write};
4+
use std::path::{Path, PathBuf};
5+
use std::process::Command;
6+
7+
const GO_LIB_NAME: &str = "go-gpa-server";
8+
9+
fn main() {
10+
let (lib_dir, lib_path) = target_path_for_go_lib();
11+
12+
println!("cargo:rustc-link-search={}", lib_dir.to_str().unwrap());
13+
println!("cargo:rustc-link-lib={GO_LIB_NAME}");
14+
15+
build_go_lib(&lib_path);
16+
generate_bindings_go_for_lib(&lib_dir)
17+
}
18+
19+
fn target_path_for_go_lib() -> (PathBuf, PathBuf) {
20+
let lib_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
21+
(
22+
lib_dir.clone(),
23+
lib_dir.join(format!("lib{GO_LIB_NAME}.so")),
24+
)
25+
}
26+
27+
fn build_go_lib(lib_path: &Path) {
28+
let mut command = Command::new("go");
29+
30+
command.env("CGO_LDFLAGS", "-Wl,--build-id=none");
31+
command.arg("build");
32+
command.arg("-ldflags=-buildid=");
33+
command.arg("-trimpath");
34+
command.arg("-o");
35+
command.arg(lib_path);
36+
37+
command.arg("-buildmode=c-shared");
38+
command.arg("lib.go");
39+
println!("cargo:rerun-if-changed=go/lib.go");
40+
command.current_dir("go");
41+
42+
let output = command.output().unwrap();
43+
if !output.status.success() {
44+
eprint!("Failed to compile go library:");
45+
stderr()
46+
.write_all(output.stderr.as_slice())
47+
.expect("Error write failed");
48+
panic!("Go lib build failed");
49+
}
50+
}
51+
52+
fn generate_bindings_go_for_lib(lib_dir: &Path) {
53+
let header = lib_dir.join("libgo-gpa-server.h");
54+
55+
let generated_bindings = PathBuf::from(env::var("OUT_DIR").unwrap()).join("go-gpa-server.rs");
56+
57+
let bindings = bindgen::Builder::default()
58+
.header(header.to_str().unwrap())
59+
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
60+
.derive_debug(false)
61+
.impl_debug(false)
62+
.default_enum_style(EnumVariation::Rust {
63+
non_exhaustive: false,
64+
})
65+
.generate()
66+
.expect("Unable to generate go lib bindings");
67+
68+
bindings
69+
.write_to_file(generated_bindings)
70+
.expect("Failed to write bindings to file");
71+
}

go-gpa-server/go/go.mod

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module cgpa
2+
3+
go 1.20
4+
5+
require github.com/ProtonMail/go-proton-api v0.4.1-0.20230628092916-81cb3f87f184
6+
7+
require (
8+
github.com/Masterminds/semver/v3 v3.2.0 // indirect
9+
github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf // indirect
10+
github.com/ProtonMail/gluon v0.16.1-0.20230523090642-633e61ce9bc2 // indirect
11+
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
12+
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect
13+
github.com/ProtonMail/go-srp v0.0.7 // indirect
14+
github.com/ProtonMail/gopenpgp/v2 v2.7.1-proton // indirect
15+
github.com/PuerkitoBio/goquery v1.8.1 // indirect
16+
github.com/andybalholm/cascadia v1.3.2 // indirect
17+
github.com/bradenaw/juniper v0.12.0 // indirect
18+
github.com/bytedance/sonic v1.9.1 // indirect
19+
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
20+
github.com/cloudflare/circl v1.3.3 // indirect
21+
github.com/cronokirby/saferith v0.33.0 // indirect
22+
github.com/emersion/go-message v0.16.0 // indirect
23+
github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594 // indirect
24+
github.com/emersion/go-vcard v0.0.0-20230331202150-f3d26859ccd3 // indirect
25+
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
26+
github.com/gin-contrib/sse v0.1.0 // indirect
27+
github.com/gin-gonic/gin v1.9.1 // indirect
28+
github.com/go-playground/locales v0.14.1 // indirect
29+
github.com/go-playground/universal-translator v0.18.1 // indirect
30+
github.com/go-playground/validator/v10 v10.14.0 // indirect
31+
github.com/go-resty/resty/v2 v2.7.0 // indirect
32+
github.com/goccy/go-json v0.10.2 // indirect
33+
github.com/google/uuid v1.3.0 // indirect
34+
github.com/json-iterator/go v1.1.12 // indirect
35+
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
36+
github.com/leodido/go-urn v1.2.4 // indirect
37+
github.com/mattn/go-isatty v0.0.19 // indirect
38+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
39+
github.com/modern-go/reflect2 v1.0.2 // indirect
40+
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
41+
github.com/pkg/errors v0.9.1 // indirect
42+
github.com/sirupsen/logrus v1.9.2 // indirect
43+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
44+
github.com/ugorji/go/codec v1.2.11 // indirect
45+
golang.org/x/arch v0.3.0 // indirect
46+
golang.org/x/crypto v0.9.0 // indirect
47+
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
48+
golang.org/x/net v0.10.0 // indirect
49+
golang.org/x/sync v0.2.0 // indirect
50+
golang.org/x/sys v0.8.0 // indirect
51+
golang.org/x/text v0.9.0 // indirect
52+
google.golang.org/protobuf v1.30.0 // indirect
53+
gopkg.in/yaml.v3 v3.0.1 // indirect
54+
)

0 commit comments

Comments
 (0)