Skip to content

Commit a710988

Browse files
committed
test: Add test for installing a dependency from gitlab and loading secrets from a JSON file.
1 parent 75048e8 commit a710988

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

src/repository/repository.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ repository_file_handle_t repository_download_package_file(const char *package_ur
118118

119119
void repository_file_finish_download(repository_file_handle_t file) {
120120
void *rc;
121-
int success = pthread_join(file->thread, &rc);
122-
if (success != 0) {
123-
printf("Failed to join thread.\n");
124-
}
121+
pthread_join(file->thread, &rc);
125122
free(rc);
126123
}
127124

test/install-from-gitlab.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
throw() {
4+
echo >&2 "$1"
5+
exit 1
6+
}
7+
8+
rm -rf tmp
9+
mkdir -p tmp
10+
cd tmp || exit
11+
12+
cat > clib.json << EOF
13+
{
14+
"registries": [
15+
"https://gitlab.com/api/v4/projects/25447829/repository/files/README.md/raw?ref=master"
16+
],
17+
"dependencies": {
18+
"nouwaarom/clib-dependency": "0.0.1"
19+
}
20+
}
21+
EOF
22+
23+
clib install -c -o tmp > /dev/null ||
24+
throw "expecting exit code of 0";
25+
26+
{ [ -d ./tmp/clib-dependency ] && [ -f ./tmp/clib-dependency/package.json ]; } ||
27+
throw "failed to install clib-dependency"
28+
29+
cd - > /dev/null || exit
30+
rm -rf ./tmp

test/package/clib_secrets.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"gitlab.com": "GitlabSecret",
3+
"github.com": "GithubSecret"
4+
}

test/package/package-secrets-load.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "describe/describe.h"
2+
#include <stdio.h>
3+
#include "clib-secrets.h"
4+
5+
int main() {
6+
describe("clib_secrets") {
7+
it("should load secrets from a valid json.") {
8+
clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json");
9+
assert(secrets != NULL);
10+
}
11+
12+
it("should provide secrets for a domain.") {
13+
clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json");
14+
char *github_secret = clib_secret_find_for_hostname(secrets, "github.com");
15+
assert(strcmp(github_secret, "GithubSecret") == 0);
16+
char *gitlab_secret = clib_secret_find_for_hostname(secrets, "gitlab.com");
17+
assert(strcmp(gitlab_secret, "GitlabSecret") == 0);
18+
}
19+
20+
return assert_failures();
21+
}
22+
}

0 commit comments

Comments
 (0)