Skip to content

Commit

Permalink
fix: abstracted all tests into seperate methods with files
Browse files Browse the repository at this point in the history
  • Loading branch information
floris-xlx committed Jul 10, 2024
1 parent 0fd560f commit d2c60b8
Show file tree
Hide file tree
Showing 26 changed files with 810 additions and 505 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ serde_json = "1.0.111"
tokio = { version = "1.37.0", features = ["full"] }
dotenv = "0.15.0"
anyhow = "1.0.86"
regex = { version = "1.10.5", optional = true }
regex = { version = "1.10.5", optional = false }


#[cfg(feature = "nightly")]

[features]
nightly = []
storage = []
rustls = []

# default = ["nightly", "storage", "realtime"]
default = ["nightly", "storage"]
# #
# #
# realtime = []
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ pub mod select;
pub mod success;
pub mod tests;
pub mod update;
pub mod request;

pub mod graphql;
pub mod nightly;
Expand Down
11 changes: 11 additions & 0 deletions src/nightly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ pub fn print_nightly_warning() {
println!("\x1b[34;1mWarning: This is a nightly build and may contain bugs.\x1b[0m");
println!("\x1b[34;1mFeatures 'Force rustls' and 'Graphql support' are currently under nightly mode.\x1b[0m");
println!("\x1b[34;1mTo disable this message, set the environment variable SUPABASE_RS_NO_NIGHTLY_MSG to 'true'.\x1b[0m");
}

pub fn print_if_dev(
message: &str
) {
dotenv().ok();
if env::var("SUPABASE_RS_DEV").unwrap_or_else(|_| "false".to_string()) == "true" {
return;
}
println!("\x1b[34m{}\x1b[0m", message);

}
52 changes: 52 additions & 0 deletions src/request/headers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::collections::HashMap;

use crate::request::Headers;


impl Headers {
pub fn new() -> Self {
Headers {
headers: HashMap::new(),
}
}

pub fn insert(&mut self, key: &str, value: &str) {
self.headers.insert(key.to_string(), value.to_string());
}

pub fn get_headers(&self) -> HashMap<String, String> {
self.headers.clone()
}
}


impl Default for Headers {
fn default() -> Self {
let mut headers = Headers::new();
headers.insert(HeadersTypes::ClientInfo.as_str(), "supabase-rs/0.3.3");
headers.insert(HeadersTypes::ContentType.as_str(), "application/json");
Headers {
headers: headers.get_headers(),
}
}
}

pub enum HeadersTypes {
ApiKey,
Authorization,
ContentType,
Prefer,
ClientInfo,
}

impl HeadersTypes {
pub fn as_str(&self) -> &str {
match self {
HeadersTypes::ApiKey => "apikey",
HeadersTypes::Authorization => "Authorization",
HeadersTypes::ContentType => "Content-Type",
HeadersTypes::Prefer => "prefer",
HeadersTypes::ClientInfo => "x_client_info",
}
}
}
8 changes: 8 additions & 0 deletions src/request/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub mod headers;

use std::collections::HashMap;


pub struct Headers {
pub headers: HashMap<String, String>,
}
16 changes: 11 additions & 5 deletions src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,17 @@
#![allow(rustdoc::invalid_rust_codeblocks)]

use crate::SupabaseClient;
use reqwest;
use reqwest::Client;
use reqwest::Response;
use crate::query::QueryBuilder;

use reqwest::{Client, Response};
use reqwest::header::HeaderMap;
use serde_json::{json, Value};

use crate::query::QueryBuilder;



#[cfg(feature = "nightly")]
use crate::nightly::print_if_dev;

impl SupabaseClient {
/// Initializes a `QueryBuilder` for a specified table.
Expand Down Expand Up @@ -167,7 +172,8 @@ impl SupabaseClient {
// Build the client and the endpoint
let endpoint: String = format!("{}/rest/v1/{}?{}", self.url, table_name, query_string);

println!("Endpoint: {}", endpoint);
#[cfg(feature = "nightly")]
println!("\x1b[33mEndpoint: {}\x1b[0m", endpoint);

#[cfg(feature = "rustls")]
let client = Client::builder().use_rustls_tls().build().unwrap();
Expand Down
Loading

0 comments on commit d2c60b8

Please sign in to comment.