Skip to content

Commit

Permalink
bridge: Reformat imports using nightly (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte authored Mar 19, 2024
1 parent 460bec2 commit 3fd0357
Show file tree
Hide file tree
Showing 26 changed files with 161 additions and 98 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/bridge-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ env:
RUST_BACKTRACE: 1

jobs:
check-fmt:
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt

- name: rustfmt
run: cargo fmt -- --check
working-directory: bridge

test-versions:
name: Webhook Bridge CI
runs-on: ubuntu-latest
Expand All @@ -32,10 +46,12 @@ jobs:
rust: [stable, beta]
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: clippy, rustfmt
components: clippy

- uses: Swatinem/rust-cache@v2
with:
workspaces: "bridge -> target"
Expand All @@ -47,10 +63,6 @@ jobs:

- uses: taiki-e/install-action@nextest

- name: rustfmt
run: cargo fmt -- --check
working-directory: bridge

- name: Install dependencies
# Packages should align with whatever is in the bridge/Dockerfile
run: |
Expand Down
2 changes: 2 additions & 0 deletions bridge/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
25 changes: 15 additions & 10 deletions bridge/svix-bridge-plugin-queue/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
pub use crate::gcp_pubsub::{GCPPubSubInputOpts, GCPPubSubOutputOpts};
pub use crate::rabbitmq::{RabbitMqInputOpts, RabbitMqOutputOpts};
pub use crate::receiver_output::QueueForwarder;
pub use crate::redis::{RedisInputOpts, RedisOutputOpts};
use crate::sender_input::QueueSender;
pub use crate::sqs::{SqsInputOpts, SqsOutputOpts};
use serde::Deserialize;
use svix_bridge_types::{
ReceiverOutput, SenderInput, SenderOutputOpts, TransformationConfig, TransformerInputFormat,
};

use crate::sender_input::QueueSender;
pub use crate::{
gcp_pubsub::{GCPPubSubInputOpts, GCPPubSubOutputOpts},
rabbitmq::{RabbitMqInputOpts, RabbitMqOutputOpts},
receiver_output::QueueForwarder,
redis::{RedisInputOpts, RedisOutputOpts},
sqs::{SqsInputOpts, SqsOutputOpts},
};

#[derive(Deserialize)]
pub struct QueueConsumerConfig {
pub name: String,
Expand Down Expand Up @@ -85,14 +88,16 @@ pub enum ReceiverOutputOpts {

#[cfg(test)]
mod tests {
use super::into_receiver_output;
use super::QueueConsumerConfig;
use crate::config::{ReceiverOutputOpts, SenderInputOpts};
use crate::redis::{RedisInputOpts, RedisOutputOpts};
use svix_bridge_types::{
SenderOutputOpts, SvixSenderOutputOpts, TransformationConfig, TransformerInputFormat,
};

use super::{into_receiver_output, QueueConsumerConfig};
use crate::{
config::{ReceiverOutputOpts, SenderInputOpts},
redis::{RedisInputOpts, RedisOutputOpts},
};

// FIXME: can't support raw payload access for redis because it requires JSON internally.
// Revisit after `omniqueue` adoption.
#[test]
Expand Down
6 changes: 4 additions & 2 deletions bridge/svix-bridge-plugin-queue/src/gcp_pubsub/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::error::{Error, Result};
use std::path::PathBuf;

use omniqueue::{backends, DynConsumer, DynProducer};
use serde::Deserialize;
use std::path::PathBuf;

use crate::error::{Error, Result};

#[derive(Debug, Default, Deserialize)]
pub struct GCPPubSubInputOpts {
Expand Down
3 changes: 2 additions & 1 deletion bridge/svix-bridge-plugin-queue/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use omniqueue::{Delivery, DynConsumer, QueueError};
use std::time::{Duration, Instant};

use omniqueue::{Delivery, DynConsumer, QueueError};
use svix_bridge_types::{
async_trait, svix::api::Svix, CreateMessageRequest, JsObject, TransformationConfig,
TransformerInput, TransformerInputFormat, TransformerJob, TransformerOutput, TransformerTx,
Expand Down
3 changes: 2 additions & 1 deletion bridge/svix-bridge-plugin-queue/src/rabbitmq/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::error::{Error, Result};
use omniqueue::{backends, DynConsumer, DynProducer};
use serde::Deserialize;

use crate::error::{Error, Result};

#[derive(Debug, Deserialize)]
pub struct RabbitMqInputOpts {
/// Connection string for RabbitMQ.
Expand Down
7 changes: 4 additions & 3 deletions bridge/svix-bridge-plugin-queue/src/receiver_output/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::config::ReceiverOutputOpts;
use crate::error::Result;
use omniqueue::DynProducer;
use std::sync::Arc;

use omniqueue::DynProducer;
use svix_bridge_types::{async_trait, ForwardRequest, ReceiverOutput};

use crate::{config::ReceiverOutputOpts, error::Result};

#[derive(Clone)]
pub struct QueueForwarder {
name: String,
Expand Down
4 changes: 2 additions & 2 deletions bridge/svix-bridge-plugin-queue/src/redis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::error::{Error, Result};
use omniqueue::{backends, DynConsumer, DynProducer};

use serde::Deserialize;

use crate::error::{Error, Result};

#[derive(Debug, Default, Deserialize)]
pub struct RedisInputOpts {
pub dsn: String,
Expand Down
11 changes: 6 additions & 5 deletions bridge/svix-bridge-plugin-queue/src/sender_input/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::config::SenderInputOpts;
use crate::{error::Error, gcp_pubsub, rabbitmq, run_inner, sqs, Consumer};
use omniqueue::DynConsumer;

use svix_bridge_types::svix::api::Svix;
use svix_bridge_types::{
async_trait, SenderInput, SenderOutputOpts, TransformationConfig, TransformerTx,
async_trait, svix::api::Svix, SenderInput, SenderOutputOpts, TransformationConfig,
TransformerTx,
};

use crate::{
config::SenderInputOpts, error::Error, gcp_pubsub, rabbitmq, run_inner, sqs, Consumer,
};

pub struct QueueSender {
Expand Down
3 changes: 2 additions & 1 deletion bridge/svix-bridge-plugin-queue/src/sqs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::error::{Error, Result};
use omniqueue::{backends, DynConsumer, DynProducer};
use serde::Deserialize;

use crate::error::{Error, Result};

#[derive(Debug, Default, Deserialize)]
pub struct SqsInputOpts {
pub queue_dsn: String,
Expand Down
23 changes: 14 additions & 9 deletions bridge/svix-bridge-plugin-queue/tests/it/gcp_pubsub_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@
//!
//! Use `run-tests.sh` to use the requisite environment for testing.
use google_cloud_googleapis::pubsub::v1::{DeadLetterPolicy, PubsubMessage};
use google_cloud_pubsub::client::{Client, ClientConfig};
use google_cloud_pubsub::subscription::{Subscription, SubscriptionConfig};
use google_cloud_pubsub::topic::Topic;
use std::time::Duration;

use google_cloud_googleapis::pubsub::v1::{DeadLetterPolicy, PubsubMessage};
use google_cloud_pubsub::{
client::{Client, ClientConfig},
subscription::{Subscription, SubscriptionConfig},
topic::Topic,
};
use serde_json::json;
use svix_bridge_plugin_queue::config::GCPPubSubInputOpts;
use svix_bridge_plugin_queue::config::SenderInputOpts;
use svix_bridge_plugin_queue::sender_input::QueueSender;
use svix_bridge_plugin_queue::{
config::{GCPPubSubInputOpts, SenderInputOpts},
sender_input::QueueSender,
};
use svix_bridge_types::{
svix::api::MessageIn, CreateMessageRequest, SenderInput, SenderOutputOpts, SvixOptions,
SvixSenderOutputOpts, TransformationConfig, TransformerInput, TransformerInputFormat,
TransformerJob, TransformerOutput,
};
use wiremock::matchers::{body_partial_json, method};
use wiremock::{Mock, MockServer, ResponseTemplate};
use wiremock::{
matchers::{body_partial_json, method},
Mock, MockServer, ResponseTemplate,
};

const DEFAULT_PUBSUB_EMULATOR_HOST: &str = "localhost:8085";

Expand Down
16 changes: 10 additions & 6 deletions bridge/svix-bridge-plugin-queue/tests/it/rabbitmq_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@
//! default guest/guest credentials.
//! Try using the `testing-docker-compose.yml` in the repo root to get this going.
use std::time::Duration;

use lapin::{
options::QueueDeclareOptions, types::FieldTable, Channel, Connection, ConnectionProperties,
Queue,
};
use serde_json::json;
use std::time::Duration;
use svix_bridge_plugin_queue::config::RabbitMqInputOpts;
use svix_bridge_plugin_queue::config::SenderInputOpts;
use svix_bridge_plugin_queue::sender_input::QueueSender;
use svix_bridge_plugin_queue::{
config::{RabbitMqInputOpts, SenderInputOpts},
sender_input::QueueSender,
};
use svix_bridge_types::{
svix::api::MessageIn, CreateMessageRequest, SenderInput, SenderOutputOpts, SvixOptions,
SvixSenderOutputOpts, TransformationConfig, TransformerInput, TransformerInputFormat,
TransformerJob, TransformerOutput,
};
use wiremock::matchers::{body_partial_json, method};
use wiremock::{Mock, MockServer, ResponseTemplate};
use wiremock::{
matchers::{body_partial_json, method},
Mock, MockServer, ResponseTemplate,
};

fn get_test_plugin(
svix_url: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ use std::time::Duration;

use redis::{AsyncCommands, Client};
use serde_json::json;
use svix_bridge_plugin_queue::config::RedisInputOpts;
use svix_bridge_plugin_queue::config::SenderInputOpts;
use svix_bridge_plugin_queue::sender_input::QueueSender;
use svix_bridge_plugin_queue::{
config::{RedisInputOpts, SenderInputOpts},
sender_input::QueueSender,
};
use svix_bridge_types::{
svix::api::MessageIn, CreateMessageRequest, SenderInput, SenderOutputOpts, SvixOptions,
SvixSenderOutputOpts, TransformationConfig, TransformerInput, TransformerInputFormat,
TransformerJob, TransformerOutput,
};
use wiremock::matchers::{body_partial_json, method};
use wiremock::{Mock, MockServer, ResponseTemplate};
use wiremock::{
matchers::{body_partial_json, method},
Mock, MockServer, ResponseTemplate,
};

fn get_test_plugin(
svix_url: String,
Expand Down
20 changes: 11 additions & 9 deletions bridge/svix-bridge-plugin-queue/tests/it/sqs_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ use std::time::Duration;

use aws_sdk_sqs::Client;
use serde_json::json;
use svix_bridge_plugin_queue::config::SenderInputOpts;
use svix_bridge_plugin_queue::config::SqsInputOpts;
use svix_bridge_plugin_queue::sender_input::QueueSender;
use svix_bridge_types::svix::api::MessageIn;
use svix_bridge_plugin_queue::{
config::{SenderInputOpts, SqsInputOpts},
sender_input::QueueSender,
};
use svix_bridge_types::{
CreateMessageRequest, SenderInput, SenderOutputOpts, SvixOptions, SvixSenderOutputOpts,
TransformationConfig, TransformerInput, TransformerInputFormat, TransformerJob,
TransformerOutput,
svix::api::MessageIn, CreateMessageRequest, SenderInput, SenderOutputOpts, SvixOptions,
SvixSenderOutputOpts, TransformationConfig, TransformerInput, TransformerInputFormat,
TransformerJob, TransformerOutput,
};
use wiremock::{
matchers::{body_partial_json, method},
Mock, MockServer, ResponseTemplate,
};
use wiremock::matchers::{body_partial_json, method};
use wiremock::{Mock, MockServer, ResponseTemplate};

const ROOT_URL: &str = "http://localhost:9324";
const DEFAULT_CFG: [(&str, &str); 3] = [
Expand Down
3 changes: 1 addition & 2 deletions bridge/svix-bridge-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ pub use async_trait::async_trait;
use serde::{Deserialize, Serialize};
pub use svix;
use svix::api::{MessageIn, PostOptions as PostOptions_, SvixOptions as _SvixOptions};
use tokio::sync::mpsc;
use tokio::sync::oneshot;
use tokio::sync::{mpsc, oneshot};

#[derive(Deserialize, Default, Eq, PartialEq, Copy, Clone)]
#[serde(rename_all = "lowercase")]
Expand Down
5 changes: 4 additions & 1 deletion bridge/svix-bridge/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use unsupported::*;
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
mod supported {
use std::sync::Arc;

use tikv_jemalloc_ctl::{epoch, stats};

pub struct AllocatorStatMibs {
Expand Down Expand Up @@ -50,8 +51,10 @@ mod supported {

#[cfg(any(target_env = "msvc", not(feature = "jemalloc")))]
mod unsupported {
use anyhow::anyhow;
use std::sync::Arc;

use anyhow::anyhow;

pub struct AllocatorStatMibs;

pub fn get_allocator_stats(
Expand Down
15 changes: 9 additions & 6 deletions bridge/svix-bridge/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::{
borrow::Cow,
collections::HashMap,
convert::Infallible,
io::{Error, ErrorKind},
net::SocketAddr,
num::NonZeroUsize,
};

use serde::Deserialize;
use shellexpand::LookupError;
use std::borrow::Cow;
use std::collections::HashMap;
use std::convert::Infallible;
use std::io::{Error, ErrorKind};
use std::net::SocketAddr;
use std::num::NonZeroUsize;
use svix_bridge_plugin_queue::config::{
into_receiver_output, QueueConsumerConfig, ReceiverOutputOpts as QueueOutOpts,
};
Expand Down
6 changes: 4 additions & 2 deletions bridge/svix-bridge/src/config/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use super::Config;
use crate::config::{LogFormat, LogLevel, SenderConfig};
use std::collections::HashMap;

use svix_bridge_plugin_queue::config::{QueueConsumerConfig, RabbitMqInputOpts, SenderInputOpts};
use svix_bridge_types::{SenderOutputOpts, SvixSenderOutputOpts};

use super::Config;
use crate::config::{LogFormat, LogLevel, SenderConfig};

/// This is meant to be a kitchen sink config, hitting as many possible
/// configuration options as possible to ensure they parse correctly.
// FIXME: today, largely based on the examples. Should instead focus on coverage.
Expand Down
Loading

0 comments on commit 3fd0357

Please sign in to comment.