Skip to content

Commit

Permalink
ci: Add workflow for tests, currently without tests that require yt-d…
Browse files Browse the repository at this point in the history
…lp or spotify credentials

To run all tests, use `make test`
  • Loading branch information
kinkard committed Jun 4, 2024
1 parent c94d164 commit 064eecb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run tests

on:
push:
branches:
- "main"

jobs:
docker:
runs-on: ubuntu-latest
steps:
# No checkout step here because build-push-action uses git context by default:
# https://github.com/marketplace/actions/build-and-push-docker-images#git-context
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and test
uses: docker/build-push-action@v5
with:
file: Dockerfile.test
cache-from: type=gha
cache-to: type=gha,mode=max
17 changes: 17 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM rust:alpine as builder

# Dependencies for some crates
RUN apk add --no-cache alpine-sdk cmake

WORKDIR /usr/src/app

# First build a dummy target to cache dependencies in a separate Docker layer
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo 'fn main() { println!("Dummy image called!"); }' > src/main.rs
RUN cargo build

# Now run tests
COPY src ./src
# Update modified attribute as otherwise cargo won't rebuild it
RUN touch -a -m ./src/main.rs
RUN cargo test
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ REVISION := $(shell git rev-parse HEAD)
docker:
docker build . --tag $(NAME):$(REVISION)
docker tag $(NAME):$(REVISION) $(NAME):latest

test:
cargo test -- --include-ignored
4 changes: 4 additions & 0 deletions src/spotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ mod tests {
}
}

#[ignore]
#[tokio::test(flavor = "multi_thread")]
async fn player_resolve_track_test() {
dotenv::dotenv().expect("Set up .env file for this test");
Expand Down Expand Up @@ -881,6 +882,7 @@ mod tests {
assert_eq!(next_stream.input.read(&mut buf).unwrap(), buf.len());
}

#[ignore]
#[tokio::test(flavor = "multi_thread")]
async fn player_resolve_album_test() {
dotenv::dotenv().expect("Set up .env file for this test");
Expand All @@ -903,6 +905,7 @@ mod tests {
}
}

#[ignore]
#[tokio::test(flavor = "multi_thread")]
async fn player_resolve_playlist_test() {
dotenv::dotenv().expect("Set up .env file for this test");
Expand All @@ -925,6 +928,7 @@ mod tests {
}
}

#[ignore]
#[tokio::test(flavor = "multi_thread")]
async fn player_resolve_other() {
dotenv::dotenv().expect("Set up .env file for this test");
Expand Down
6 changes: 4 additions & 2 deletions src/yt_dlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,9 @@ mod tests {
use pretty_assertions::assert_eq;
use std::time::Duration;

#[ignore]
#[tokio::test]
async fn test_ytdlp_rick_roll() {
async fn resolve_rick_roll() {
let mut yt_dlp = YtDlp::new(Client::new(), "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
.await
.unwrap();
Expand All @@ -329,8 +330,9 @@ mod tests {
);
}

#[ignore]
#[tokio::test]
async fn test_ytdlp_pritoptat() {
async fn resolve_pritoptat() {
let mut yt_dlp = YtDlp::new(Client::new(), "притоптать").await.unwrap();

let metadata = yt_dlp.aux_metadata().await.unwrap();
Expand Down

0 comments on commit 064eecb

Please sign in to comment.