Skip to content

Commit

Permalink
Add test for subgraph introspect (#2003)
Browse files Browse the repository at this point in the history
Adds new tests for the `subgraph introspect` command, as well as the `--watch` functionality it provides. Further I've updated some of the framework aspects to make them slightly easier to use, especially as regards choosing ports which is now handled by a library.
  • Loading branch information
jonathanrainer committed Jul 26, 2024
1 parent 7dbf2da commit 9b49532
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ jobs:
env:
APOLLO_ROVER_DEV_COMPOSITION_VERSION: ${{ matrix.composition-version }}
APOLLO_ROVER_DEV_ROUTER_VERSION: ${{ matrix.router-version }}
CARGO_MANIFEST_DIR: ${{ github.workspace }}
run: |
E2E_BINARY=$(find ./${{ matrix.testing_target.binary_under_test }}/deps -type f ! -name "*.*" -and -name "e2e-*")
echo "Found '$E2E_BINARY'"
Expand All @@ -118,6 +119,7 @@ jobs:
APOLLO_ROVER_DEV_COMPOSITION_VERSION: ${{ matrix.composition-version }}
APOLLO_ROVER_DEV_ROUTER_VERSION: ${{ matrix.router-version }}
CARGO_BIN_EXE_rover: ${{ github.workspace }}\${{ matrix.testing_target.binary_under_test }}\rover.exe
CARGO_MANIFEST_DIR: ${{ github.workspace }}
run: |
$E2E_BINARY=Get-ChildItem -Path .\${{ matrix.testing_target.binary_under_test }}\deps -File | Where-Object { $_.Name -like 'e2e-*.exe' } | ForEach-Object { $_.FullName }
Write-Output "Found '$E2E_BINARY'"
Expand Down
90 changes: 81 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,16 @@ url = { workspace = true, features = ["serde"] }
assert_cmd = { workspace = true }
assert_fs = { workspace = true }
assert-json-diff = { workspace = true }
dircpy = "0.3.18"
duct = "0.13.7"
git2 = { workspace = true, features = ["https"]}
httpmock = { workspace = true }
mime = "0.3.17"
portpicker = "0.1.1"
predicates = { workspace = true }
reqwest = { workspace = true, features = ["blocking", "native-tls-vendored"] }
rstest = { workspace = true }
serial_test = { workspace = true }
speculoos = { workspace = true }
tokio = { workspace = true }
tracing-test = "0.2.5"
2 changes: 1 addition & 1 deletion examples/supergraph-demo/pandas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "pandas.mjs",
"scripts": {
"start": "nodemon -e mjs,graphql",
"start": "nodemon -e mjs,graphql pandas.mjs",
"dev": "cargo rover dev --name pandas --url http://localhost:4003",
"clean": "rm -rf node_modules package-lock.json"
},
Expand Down
14 changes: 8 additions & 6 deletions examples/supergraph-demo/pandas/pandas.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { buildSubgraphSchema } from '@apollo/subgraph';
import { readFileSync } from 'fs';
import { gql } from 'graphql-tag';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import {buildSubgraphSchema} from '@apollo/subgraph';
import {readFileSync} from 'fs';
import {gql} from 'graphql-tag';
import {ApolloServer} from '@apollo/server';
import {startStandaloneServer} from '@apollo/server/standalone';

const typeDefs = gql(readFileSync('./pandas.graphql', { encoding: 'utf-8' }).toString());

Expand All @@ -26,5 +26,7 @@ const server = new ApolloServer({
schema: buildSubgraphSchema({ typeDefs, resolvers })
});

const { url } = await startStandaloneServer(server, { listen: { port: 4003 } });
const port = parseInt(process.argv[2], 10) || 4003

const { url } = await startStandaloneServer(server, { listen: { port: port } });
console.log(`🚀 Pandas server ready at ${url}`);
12 changes: 8 additions & 4 deletions tests/e2e/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ use std::time::Duration;

use assert_cmd::prelude::CommandCargoExt;
use mime::APPLICATION_JSON;
use portpicker::pick_unused_port;
use reqwest::header::CONTENT_TYPE;
use reqwest::Client;
use rstest::*;
use serde_json::{json, Value};
use speculoos::assert_that;
use tempfile::TempDir;
use tokio::time::timeout;
use tracing::error;
use tracing_test::traced_test;

use crate::e2e::{
run_subgraphs_retail_supergraph, test_graphql_connection, GRAPHQL_TIMEOUT_DURATION,
};

const ROVER_DEV_TIMEOUT: Duration = Duration::from_secs(45);
const ROUTER_PORT: u32 = 4123;

#[fixture]
#[once]
fn run_rover_dev(#[from(run_subgraphs_retail_supergraph)] working_dir: &TempDir) -> String {
let mut cmd = Command::cargo_bin("rover").expect("Could not find necessary binary");
let router_url = format!("http://localhost:{}", ROUTER_PORT);
let port = pick_unused_port().expect("No ports free");
let router_url = format!("http://localhost:{}", port);
let client = Client::new();

cmd.args([
Expand All @@ -33,7 +36,7 @@ fn run_rover_dev(#[from(run_subgraphs_retail_supergraph)] working_dir: &TempDir)
"--router-config",
"router-config-dev.yaml",
"--supergraph-port",
&format!("{}", ROUTER_PORT),
&format!("{}", port),
"--elv2-license",
"accept",
]);
Expand Down Expand Up @@ -64,6 +67,7 @@ fn run_rover_dev(#[from(run_subgraphs_retail_supergraph)] working_dir: &TempDir)
#[case::deprecated_introspection("query {__type(name:\"Review\"){ fields(includeDeprecated: true) { name isDeprecated deprecationReason } } }", json!({"data":{"__type":{"fields":[{"name":"id","isDeprecated":false,"deprecationReason":null},{"name":"body","isDeprecated":false,"deprecationReason":null},{"name":"author","isDeprecated":true,"deprecationReason":"Use the new `user` field"},{"name":"user","isDeprecated":false,"deprecationReason":null},{"name":"product","isDeprecated":false,"deprecationReason":null}]}}}))]
#[ignore]
#[tokio::test(flavor = "multi_thread")]
#[traced_test]
async fn e2e_test_rover_dev(
#[from(run_rover_dev)] router_url: &str,
#[case] query: String,
Expand All @@ -85,7 +89,7 @@ async fn e2e_test_rover_dev(
break;
}
Err(e) => {
println!("Error: {}", e)
error!("Error: {}", e)
}
};
}
Expand Down
Loading

0 comments on commit 9b49532

Please sign in to comment.