Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check all object's id in test code #306

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ smallvec = "1.11"
tokio = { version = "1.35.1", features = ["macros"] }
clap = { version = "4.4.11", features = ["derive"] }



[dev-dependencies]
reqwest = {version = "0.11.23", features = ["stream", "json"]}
env_logger = "0.10.1"
Expand All @@ -36,7 +34,7 @@ tokio-util = "0.7.10"
go-defer = "0.1.0"
bytes = "1.5.0"
git2 = "0.18.1"

toml = "0.8.8"

[build-dependencies]
shadow-rs = "0.26.0"
24 changes: 12 additions & 12 deletions gateway/src/api_service/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ pub fn routers<S>(state: ApiServiceState) -> Router<S> {
.with_state(state)
}

async fn life_cycle_check() -> Result<impl IntoResponse, (StatusCode, String)> {
Ok(Json("http ready"))
}

async fn get_count_nums(
Query(query): Query<HashMap<String, String>>,
state: State<ApiServiceState>,
) -> Result<Json<GitTypeCounter>, (StatusCode, String)> {
let repo_path = query.get("repo_path").unwrap();
state.object_service.count_object_num(repo_path).await
}

async fn get_blob_object(
Query(query): Query<HashMap<String, String>>,
state: State<ApiServiceState>,
Expand All @@ -67,3 +55,15 @@ async fn get_origin_object(
let repo_path = query.get("repo_path").expect("repo_path is required");
state.object_service.get_objects_data(object_id, repo_path).await
}

async fn life_cycle_check() -> Result<impl IntoResponse, (StatusCode, String)> {
Ok(Json("http ready"))
}

async fn get_count_nums(
Query(query): Query<HashMap<String, String>>,
state: State<ApiServiceState>,
) -> Result<Json<GitTypeCounter>, (StatusCode, String)> {
let repo_path = query.get("repo_path").unwrap();
state.object_service.count_object_num(repo_path).await
}
4 changes: 2 additions & 2 deletions sql/postgres/pg_20240115__init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CREATE TABLE IF NOT EXISTS "node" (
"full_path" TEXT NOT NULL,
"created_at" TIMESTAMP NOT NULL,
"updated_at" TIMESTAMP NOT NULL,
CONSTRAINT uniq_n_git_path UNIQUE (git_id, repo_path);
CONSTRAINT uniq_n_git_path UNIQUE (git_id, repo_path)
);
CREATE INDEX "idx_node_git_id" ON "node" ("git_id");
CREATE INDEX "idx_node_name" ON "node" ("name");
Expand All @@ -45,7 +45,7 @@ CREATE TABLE IF NOT EXISTS "refs" (
"ref_git_id" VARCHAR(40) NOT NULL,
"created_at" TIMESTAMP NOT NULL,
"updated_at" TIMESTAMP NOT NULL,
CONSTRAINT uniq_ref_path_name UNIQUE (repo_path, ref_name);
CONSTRAINT uniq_ref_path_name UNIQUE (repo_path, ref_name)
);
CREATE INDEX "idx_refs_repo_path" ON "refs" ("repo_path");

Expand Down
17 changes: 5 additions & 12 deletions storage/src/driver/database/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ pub trait ObjectStorage: Send + Sync {

async fn save_refs(&self, save_models: Vec<refs::ActiveModel>) -> Result<bool, MegaError> {
refs::Entity::insert_many(save_models)
.on_conflict(
OnConflict::columns(vec![refs::Column::RepoPath, refs::Column::RefName])
.update_columns([refs::Column::RefGitId, refs::Column::UpdatedAt])
.to_owned(),
)
.exec(self.get_connection())
.await
.unwrap();
Expand Down Expand Up @@ -285,18 +290,6 @@ pub trait ObjectStorage: Send + Sync {
.await
.unwrap())
}
// async fn get_nodes(&self) -> Result<Vec<node::Model>, MegaError> {
// Ok(node::Entity::find()
// .select_only()
// .columns([
// node::Column::GitId,
// node::Column::Size,
// node::Column::FullPath,
// ])
// .all(self.get_connection())
// .await
// .unwrap())
// }

async fn save_nodes(
&self,
Expand Down
32 changes: 12 additions & 20 deletions tests/common_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use std::{
io::Cursor,
process::Command,
thread::{self, sleep},
time::Duration,
time::Duration, path::PathBuf,
};

use bytes::Bytes;
use futures_util::StreamExt;
use git2::Repository;
use serde::{Deserialize, Serialize};
use tokio_util::io::ReaderStream;

use git::internal::pack::counter::GitTypeCounter;
Expand All @@ -23,16 +24,24 @@ pub struct P2pTestConfig {
pub commit_id: String,
pub sub_commit_id: String,
pub counter: GitTypeCounter,
pub clone_path: PathBuf,
}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct PackObjectIds {
pub commit_ids: Vec<String>,
pub tree_ids: Vec<String>,
pub blob_ids: Vec<String>,
pub tag_ids: Vec<String>,
}

// TODO: got some problem on copy content files
// pub fn build_image(config: &P2pTestConfig) {
// // println!("current:{:?}", env::current_dir().unwrap());
// let mut child = Command::new("docker")
// .arg("compose")
// .arg("-f")
// .arg(&config.compose_path)
// .arg("build")
// .current_dir(env::current_dir().unwrap())
// .spawn()
// .expect("Failed to execute command");
// assert!(child.wait().is_ok());
Expand Down Expand Up @@ -72,23 +81,6 @@ pub async fn lifecycle_check(config: &P2pTestConfig) {
}
}

// pub fn init_by_command() {
// let res = Command::new("git")
// .arg("remote")
// .arg("set-url")
// .arg("local")
// .arg("http://localhost:8000/projects/mega.git")
// .output()
// .expect("Failed to execute command");
// assert!(res.status.success());
// let res2 = Command::new("git")
// .arg("push")
// .arg("local")
// .arg("main")
// .output()
// .expect("Failed to execute command");
// assert!(res2.status.success());
// }

pub async fn init_by_pack(config: &P2pTestConfig) {
let mut source = env::current_dir().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/compose/http/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
ports:
- "5433:5432"
volumes:
- ../../../sql/postgres/pg_20231106__init.sql:/docker-entrypoint-initdb.d/init.sql
- ../../../sql/postgres/pg_20240115__init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
4 changes: 2 additions & 2 deletions tests/compose/mega_p2p/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ services:
ports:
- "5433:5432"
volumes:
- ../../../sql/postgres/pg_20231106__init.sql:/docker-entrypoint-initdb.d/init.sql
- ../../../sql/postgres/pg_20240115__init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand All @@ -65,7 +65,7 @@ services:
ports:
- "5434:5432"
volumes:
- ../../../sql/postgres/pg_20231106__init.sql:/docker-entrypoint-initdb.d/init.sql
- ../../../sql/postgres/pg_20240115__init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
Loading
Loading