diff --git a/src/composition/supergraph/binary.rs b/src/composition/supergraph/binary.rs index 2f2f1fe3f..5321714d3 100644 --- a/src/composition/supergraph/binary.rs +++ b/src/composition/supergraph/binary.rs @@ -194,6 +194,11 @@ mod tests { Version::from_str("2.9.0").unwrap() } + #[fixture] + fn supergraph_config_path() -> Utf8PathBuf { + Utf8PathBuf::from_str("dummy_supergraph_config_path").unwrap() + } + #[fixture] fn build_output() -> String { "{\"Ok\":{\"supergraphSdl\":\"schema\\n @link(url: \\\"https://specs.apollo.dev/link/v1.0\\\")\\n @link(url: \\\"https://specs.apollo.dev/join/v0.3\\\", for: EXECUTION)\\n @link(url: \\\"https://specs.apollo.dev/tag/v0.3\\\", import: [\\\"@tag\\\"])\\n @link(url: \\\"https://specs.apollo.dev/inaccessible/v0.2\\\", import: [\\\"@inaccessible\\\"], for: SECURITY)\\n{\\n query: Query\\n}\\n\\ndirective @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION\\n\\ndirective @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE\\n\\ndirective @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION\\n\\ndirective @join__graph(name: String!, url: String!) on ENUM_VALUE\\n\\ndirective @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE\\n\\ndirective @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR\\n\\ndirective @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION\\n\\ndirective @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA\\n\\ndirective @tag(name: String!) repeatable on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | SCHEMA\\n\\nscalar join__FieldSet\\n\\nenum join__Graph {\\n PANDAS @join__graph(name: \\\"pandas\\\", url: \\\"http://localhost:4003\\\")\\n PRODUCTS @join__graph(name: \\\"products\\\", url: \\\"http://localhost:4002\\\")\\n USERS @join__graph(name: \\\"users\\\", url: \\\"http://localhost:4001\\\")\\n}\\n\\nscalar link__Import \\n\\nenum link__Purpose {\\n \\\"\\\"\\\"\\n `SECURITY` features provide metadata necessary to securely resolve fields.\\n \\\"\\\"\\\"\\n SECURITY\\n\\n \\\"\\\"\\\"\\n `EXECUTION` features provide metadata necessary for operation execution.\\n \\\"\\\"\\\"\\n EXECUTION\\n}\\n\\ntype Panda\\n @join__type(graph: PANDAS)\\n{\\n name: ID!\\n favoriteFood: String @tag(name: \\\"nom-nom-nom\\\")\\n}\\n\\ntype Product implements ProductItf & SkuItf\\n @join__implements(graph: PRODUCTS, interface: \\\"ProductItf\\\")\\n @join__implements(graph: PRODUCTS, interface: \\\"SkuItf\\\")\\n @join__type(graph: PRODUCTS, key: \\\"id\\\")\\n @join__type(graph: PRODUCTS, key: \\\"sku package\\\")\\n @join__type(graph: PRODUCTS, key: \\\"sku variation { id }\\\")\\n{\\n id: ID! @tag(name: \\\"hi-from-products\\\")\\n sku: String\\n package: String\\n variation: ProductVariation\\n dimensions: ProductDimension\\n createdBy: User\\n hidden: String\\n}\\n\\ntype ProductDimension\\n @join__type(graph: PRODUCTS)\\n{\\n size: String\\n weight: Float\\n}\\n\\ninterface ProductItf implements SkuItf\\n @join__implements(graph: PRODUCTS, interface: \\\"SkuItf\\\")\\n @join__type(graph: PRODUCTS)\\n{\\n id: ID!\\n sku: String\\n package: String\\n variation: ProductVariation\\n dimensions: ProductDimension\\n createdBy: User\\n hidden: String @inaccessible\\n}\\n\\ntype ProductVariation\\n @join__type(graph: PRODUCTS)\\n{\\n id: ID!\\n}\\n\\ntype Query\\n @join__type(graph: PANDAS)\\n @join__type(graph: PRODUCTS)\\n @join__type(graph: USERS)\\n{\\n allPandas: [Panda] @join__field(graph: PANDAS)\\n panda(name: ID!): Panda @join__field(graph: PANDAS)\\n allProducts: [ProductItf] @join__field(graph: PRODUCTS)\\n product(id: ID!): ProductItf @join__field(graph: PRODUCTS)\\n}\\n\\nenum ShippingClass\\n @join__type(graph: PRODUCTS)\\n{\\n STANDARD @join__enumValue(graph: PRODUCTS)\\n EXPRESS @join__enumValue(graph: PRODUCTS)\\n}\\n\\ninterface SkuItf\\n @join__type(graph: PRODUCTS)\\n{\\n sku: String\\n}\\n\\ntype User\\n @join__type(graph: PRODUCTS, key: \\\"email\\\")\\n @join__type(graph: USERS, key: \\\"email\\\")\\n{\\n email: ID! @tag(name: \\\"test-from-users\\\")\\n totalProductsCreated: Int\\n name: String @join__field(graph: USERS)\\n}\",\"hints\":[{\"message\":\"[UNUSED_ENUM_TYPE]: Enum type \\\"ShippingClass\\\" is defined but unused. It will be included in the supergraph with all the values appearing in any subgraph (\\\"as if\\\" it was only used as an output type).\",\"code\":\"UNUSED_ENUM_TYPE\",\"nodes\":[],\"omittedNodesCount\":0}]}}".to_string() @@ -243,9 +248,32 @@ mod tests { assert_that!(result_output_target).is_equal_to(expected_output_target); } + #[rstest] + #[case::with_output_path(OutputTarget::File(Utf8PathBuf::from_str("some_output_file").unwrap()), vec!["compose", "dummy_supergraph_config_path", "some_output_file"])] + #[case::without_output_path(OutputTarget::Stdout, vec!["compose", "dummy_supergraph_config_path"])] + fn test_prepare_compose_args( + #[case] test_output_target: OutputTarget, + #[case] expected_args: Vec<&str>, + supergraph_config_path: Utf8PathBuf, + ) { + let supergraph_version = SupergraphVersion::new(fed_two_eight()); + let binary_path = Utf8PathBuf::from_str("/tmp/supergraph").unwrap(); + //let output_target = OutputTarget::Stdout; + + let supergraph_binary = SupergraphBinary { + exe: binary_path.clone(), + version: supergraph_version, + output_target: test_output_target, + }; + + let args = supergraph_binary.prepare_compose_args(&supergraph_config_path); + + assert_eq!(args, expected_args); + } + #[rstest] #[tokio::test] - async fn test_compose( + async fn test_compose_success( build_output: String, composition_output: CompositionSuccess, ) -> Result<()> { @@ -272,7 +300,7 @@ mod tests { let mut mock_read_file = MockReadFile::new(); mock_read_file.expect_read_file().times(0); let mut mock_exec = MockExecCommand::new(); - let build_output_blah = build_output.clone(); + let build_output = build_output.clone(); mock_exec .expect_exec_command() @@ -284,7 +312,7 @@ mod tests { .returning(move |_, _| { Ok(Output { status: ExitStatus::default(), - stdout: build_output_blah.clone().as_bytes().into(), + stdout: build_output.clone().as_bytes().into(), stderr: Vec::default(), }) });