diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a937273..4a38855 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,17 +8,18 @@ on: tags: - 'v*' - jobs: CI: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: install Rust - run: | - git submodule update --init --recursive - rustup toolchain install stable --component clippy --component rustfmt - - name: Format - run: cargo fmt -- --check - - name: clippy - run: cargo clippy + with: + submodules: 'recursive' + - name: Install Rust toolchain + run: rustup toolchain install stable --component clippy --component rustfmt + - name: Run format + run: cargo fmt --all -- --check + - name: Run clippy + run: cargo clippy --workspace --tests -- -D warnings + - name: Run tests + run: cargo test --workspace diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index a581102..9444710 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -22,4 +22,4 @@ jobs: pip3 install --upgrade pip pip3 install setuptools pip3 install -r requirements.txt - python3 tests/e2e/run_e2e.py --expected_file=tests/e2e/data/expected_context.yaml --max_retry_times=3 --target_path=/ping + python3 e2e/run_e2e.py --expected_file=e2e/data/expected_context.yaml --max_retry_times=3 --target_path=/ping diff --git a/.gitignore b/.gitignore index 11469bd..b08a9eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /target -/tests/e2e/target +/tests/target .idea/ diff --git a/docker-compose.e2e.yml b/docker-compose.e2e.yml index 875fbaf..a817550 100644 --- a/docker-compose.e2e.yml +++ b/docker-compose.e2e.yml @@ -13,7 +13,7 @@ services: consumer: build: context: . - dockerfile: ./tests/e2e/docker/Dockerfile + dockerfile: ./e2e/docker/Dockerfile expose: - 8082 command: --mode consumer @@ -28,7 +28,7 @@ services: producer: build: context: . - dockerfile: ./tests/e2e/docker/Dockerfile + dockerfile: ./e2e/docker/Dockerfile ports: - "8081:8081" command: --mode producer diff --git a/tests/e2e/Cargo.lock b/e2e/Cargo.lock similarity index 100% rename from tests/e2e/Cargo.lock rename to e2e/Cargo.lock diff --git a/tests/e2e/Cargo.toml b/e2e/Cargo.toml similarity index 86% rename from tests/e2e/Cargo.toml rename to e2e/Cargo.toml index 0e3c003..1137c42 100644 --- a/tests/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Shikugawa "] edition = "2021" [dependencies] -skywalking_rust = { path = "../.." } +skywalking_rust = { path = ".." } hyper = { version = "0.14", features = ["full"] } tokio = { version = "1", features = ["full"] } structopt = "0.3" diff --git a/tests/e2e/data/expected_context.yaml b/e2e/data/expected_context.yaml similarity index 100% rename from tests/e2e/data/expected_context.yaml rename to e2e/data/expected_context.yaml diff --git a/e2e/docker/Dockerfile b/e2e/docker/Dockerfile new file mode 100644 index 0000000..8f861f7 --- /dev/null +++ b/e2e/docker/Dockerfile @@ -0,0 +1,5 @@ +FROM rust:1.57 +WORKDIR /build +COPY . /build/ +RUN cd e2e && cargo build --release --locked +ENTRYPOINT ["/build/e2e/target/release/e2e"] diff --git a/tests/e2e/run_e2e.py b/e2e/run_e2e.py similarity index 100% rename from tests/e2e/run_e2e.py rename to e2e/run_e2e.py diff --git a/tests/e2e/rust-toolchain.toml b/e2e/rust-toolchain.toml similarity index 100% rename from tests/e2e/rust-toolchain.toml rename to e2e/rust-toolchain.toml diff --git a/tests/e2e/src/main.rs b/e2e/src/main.rs similarity index 100% rename from tests/e2e/src/main.rs rename to e2e/src/main.rs diff --git a/src/reporter/grpc.rs b/src/reporter/grpc.rs index 4b0c690..218383c 100644 --- a/src/reporter/grpc.rs +++ b/src/reporter/grpc.rs @@ -48,7 +48,10 @@ impl Reporter { /// # Example /// /// ```no_run + /// use std::error::Error; + /// /// use tokio; + /// /// use skywalking_rust::context::trace_context::TracingContext; /// use skywalking_rust::reporter::grpc::Reporter; /// diff --git a/tests/e2e/docker/Dockerfile b/tests/e2e/docker/Dockerfile deleted file mode 100644 index ebce92c..0000000 --- a/tests/e2e/docker/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM rust:1.57 as build -WORKDIR /build -COPY . /build/ -RUN cd tests/e2e && cargo build --release --locked -ENTRYPOINT ["/build/tests/e2e/target/release/e2e"] diff --git a/tests/propagation.rs b/tests/propagation.rs index 99ad4fb..b4cd61e 100644 --- a/tests/propagation.rs +++ b/tests/propagation.rs @@ -35,7 +35,7 @@ fn basic() { let data = "1-MQ==-NQ==-3-bWVzaA==-aW5zdGFuY2U=-L2FwaS92MS9oZWFsdGg=-ZXhhbXBsZS5jb206ODA4MA=="; let res = decode_propagation(data).unwrap(); - assert_eq!(res.do_sample, true); + assert!(res.do_sample); assert_eq!(res.parent_trace_id, "1"); assert_eq!(res.parent_trace_segment_id, "5"); assert_eq!(res.parent_span_id, 3); @@ -50,7 +50,7 @@ fn less_field() { let data = "1-MQ==-NQ==-3-bWVzaA==-aW5zdGFuY2U=-L2FwaS92MS9oZWFsdGg="; let res = decode_propagation(data); - assert_eq!(res.is_err(), true); + assert!(res.is_err()); } #[test] @@ -58,7 +58,7 @@ fn more_field() { let data = "1-MQ==-NQ==-3-bWVzaA==-aW5zdGFuY2U=-L2FwaS92MS9oZWFsdGg=-ZXhhbXBsZS5jb206ODA4MA==-hogehoge"; let res = decode_propagation(data); - assert_eq!(res.is_err(), true); + assert!(res.is_err()); } #[test] @@ -66,7 +66,7 @@ fn invalid_sample() { let data = "3-MQ==-NQ==-3-bWVzaA==-aW5zdGFuY2U=-L2FwaS92MS9oZWFsdGg=-ZXhhbXBsZS5jb206ODA4MA=="; let res = decode_propagation(data); - assert_eq!(res.is_err(), true); + assert!(res.is_err()); } #[test] @@ -75,7 +75,7 @@ fn basic_encode() { let tc = TracingContext::default_internal(Arc::new(time_fetcher), "mesh", "instance"); let res = encode_propagation(&tc, "/api/v1/health", "example.com:8080"); let res2 = decode_propagation(&res).unwrap(); - assert_eq!(true, res2.do_sample); + assert!(res2.do_sample); assert_eq!("/api/v1/health", res2.destination_endpoint); assert_eq!("example.com:8080", res2.destination_address) } diff --git a/tests/trace_context.rs b/tests/trace_context.rs index eea0d0a..af1eb21 100644 --- a/tests/trace_context.rs +++ b/tests/trace_context.rs @@ -66,9 +66,7 @@ fn create_span() { { let mut span1 = context.create_entry_span("op1").unwrap(); - let mut logs = Vec::<(&str, &str)>::new(); - logs.push(("hoge", "fuga")); - logs.push(("hoge2", "fuga2")); + let logs = vec![("hoge", "fuga"), ("hoge2", "fuga2")]; let expected_log_message = logs .to_owned() .into_iter() @@ -80,15 +78,13 @@ fn create_span() { } }) .collect(); - let mut expected_log = Vec::::new(); - expected_log.push(Log { + let expected_log = vec![Log { time: 100, data: expected_log_message, - }); + }]; span1.add_log(logs); - let mut tags = Vec::<(&str, &str)>::new(); - tags.push(("hoge", "fuga")); + let tags = vec![("hoge", "fuga")]; let expected_tags = tags .to_owned() .into_iter() @@ -100,7 +96,7 @@ fn create_span() { } }) .collect(); - span1.add_tag(tags[0].clone()); + span1.add_tag(tags[0]); let span1_expected = SpanObject { span_id: 1, @@ -124,7 +120,7 @@ fn create_span() { { let span2 = context.create_entry_span("op2"); - assert_eq!(span2.is_err(), true); + assert!(span2.is_err()); } { @@ -150,11 +146,11 @@ fn create_span() { } let segment = context.convert_segment_object(); - assert_eq!(segment.trace_id.len() != 0, true); - assert_eq!(segment.trace_segment_id.len() != 0, true); + assert_ne!(segment.trace_id.len(), 0); + assert_ne!(segment.trace_segment_id.len(), 0); assert_eq!(segment.service, "service"); assert_eq!(segment.service_instance, "instance"); - assert_eq!(segment.is_size_limited, false); + assert!(!segment.is_size_limited); } #[test] @@ -170,11 +166,11 @@ fn create_span_from_context() { ); let segment = context.convert_segment_object(); - assert_eq!(segment.trace_id.len() != 0, true); - assert_eq!(segment.trace_segment_id.len() != 0, true); + assert_ne!(segment.trace_id.len(), 0); + assert_ne!(segment.trace_segment_id.len(), 0); assert_eq!(segment.service, "service2"); assert_eq!(segment.service_instance, "instance2"); - assert_eq!(segment.is_size_limited, false); + assert!(!segment.is_size_limited); } #[test]