Skip to content

Commit

Permalink
fixes tests and clippy issues, locks onto a Rust version (#69)
Browse files Browse the repository at this point in the history
* don't build with beta

* locks rust to 1.63, fixes tests and clippy errors

* hope CI installs the rust version from the toml file

* adds a Justfile

* removes broken examples

* simplify CI to only run `just ci`
  • Loading branch information
TimSimpson authored Sep 16, 2022
1 parent dada6a8 commit af71fee
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 267 deletions.
27 changes: 6 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-18.04, windows-2019, macos-11]
rust: [stable, beta]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1
- name: Install
run: rustup default ${{ matrix.rust }}
- name: Build
run: cargo check

linting:
name: Linting
needs: build
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Install
run: |
rustup component add clippy-preview
rustup component add rustfmt
- name: Linting
run: cargo clippy -- -D warnings
- name: Formatting
run: cargo fmt -- --check
- name: checkout
uses: actions/checkout@v1
- name: install Just
run: cargo install just --version 1.2.0
- name: Build and Test
run: just ci
36 changes: 36 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# just manual: https://github.com/casey/just/#readme

_default:
@just --list

# Runs clippy on the sources
check:
cargo clippy --locked --tests -- -D warnings

# removes all build artifacts
clean:
rm -r target

# builds nexus
build:
cargo build --locked

# builds in release mode
build-release:
cargo build --locked --release

# Formats the code base
fmt:
cargo fmt

# runs tests
test:
cargo test --locked

# runs the same checks performed by the CI job
ci:
just fmt
git diff --exit-code
just check
just build
just test
4 changes: 0 additions & 4 deletions base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ hyper = "0.14.11"
[dev-dependencies]
regex = "1.5.4"
tokio = { version = "1.18", features = ["macros", "fs"] }

[examples]
name = "create-token"
path = "examples/create-token.rs"
45 changes: 0 additions & 45 deletions base/examples/create-token.rs

This file was deleted.

52 changes: 0 additions & 52 deletions base/examples/list_organizations.rs

This file was deleted.

2 changes: 1 addition & 1 deletion base/src/errors/api_response_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::problem_details::ProblemDetails;
use reqwest::StatusCode;

/// Represents an error reported by an API operation
#[derive(Clone, PartialEq)]
#[derive(Clone, PartialEq, Eq)]
pub struct ApiResponseError {
pub status_code: StatusCode,
pub problem_details: ProblemDetails,
Expand Down
32 changes: 1 addition & 31 deletions base/src/errors/problem_details.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

/// Represents a problem reported from the API
#[derive(Clone, PartialEq, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProblemDetails {
#[serde(skip_serializing_if = "Option::is_none")]
pub detail: Option<String>,
Expand Down Expand Up @@ -37,33 +37,3 @@ impl std::fmt::Debug for ProblemDetails {
writeln!(f, "{}", self)
}
}

#[cfg(test)]
mod tests {
use super::*;
use regex::Regex;

#[test]
fn problem_details_display() {
let mut fields = HashMap::new();
fields.insert("field1".to_string(), "value1".to_string());
fields.insert("field2".to_string(), "value2".to_string());
let pd = ProblemDetails {
detail: "Details Here".to_string(),
fields,
instance: "Instance".to_string(),
status: "Status".to_string(),
title: "Title".to_string(),
_type: "Type".to_string(),
};
let expected = r#"\{"detail": "Details Here", "fields": (\{"field1": "value1", "field2": "value2"\}|\{"field2": "value2", "field1": "value1"\}), "instance": "Instance", "status": "Status", "title": "Title", "type": "Type"\}"#;
let actual = format!("{}", pd);
let expected_re = Regex::new(expected).unwrap();
assert!(
expected_re.is_match(&actual),
"Error: expected {}, actual {}",
expected,
actual
);
}
}
108 changes: 0 additions & 108 deletions base/tests/_dyn_error_tests._rs

This file was deleted.

10 changes: 6 additions & 4 deletions base/tests/error_tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use esc_api_base::errors::*;
use esc_client_base::errors::ApiResponseError;
use esc_client_base::errors::ProblemDetails;
use esc_client_base::errors::Result;

fn get_api_error() -> std::result::Result<i32, ApiResponseError> {
let status_code = reqwest::StatusCode::INTERNAL_SERVER_ERROR;
let problem_details = ProblemDetails {
details: "Details Here".to_string(),
detail: Some("Details Here".to_string()),
fields: Default::default(),
instance: "Instance".to_string(),
status: "Status".to_string(),
status: 200,
title: "Title".to_string(),
_type: "Type".to_string(),
};
Expand All @@ -33,7 +35,7 @@ fn expect_error() -> Result<u16> {
}
}

async fn some_async_function() -> () {
async fn some_async_function() {
use std::time::Duration;
use tokio::time::sleep;
sleep(Duration::new(10, 0)).await;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/v1/integrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::resources::OrgId;
// Deleted,
// }

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "sink")]
pub enum IntegrationData {
#[serde(rename = "opsGenie")]
Expand Down
1 change: 1 addition & 0 deletions generated/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::derive_partial_eq_without_eq)]
#[macro_use]
extern crate serde_derive;
pub mod access;
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.63.0"
components = ["rustfmt", "clippy"]

0 comments on commit af71fee

Please sign in to comment.