@@ -745,13 +745,66 @@ func newPtr[T int | string](str T) *T {
745745func TestValidateGraph (t * testing.T ) {
746746 testCases := map [string ]struct {
747747 connectorCfg map [component.ID ]component.Config
748+ receiverCfg map [component.ID ]component.Config
749+ exporterCfg map [component.ID ]component.Config
748750 pipelinesCfg pipelines.Config
749751 expectedError string
750752 }{
753+ "Valid connector usage" : {
754+ connectorCfg : map [component.ID ]component.Config {
755+ component .NewIDWithName (nopType , "connector1" ): & struct {}{},
756+ },
757+ receiverCfg : map [component.ID ]component.Config {
758+ component .NewID (nopType ): & struct {}{},
759+ },
760+ exporterCfg : map [component.ID ]component.Config {
761+ component .NewID (nopType ): & struct {}{},
762+ },
763+ pipelinesCfg : pipelines.Config {
764+ pipeline .NewIDWithName (pipeline .SignalLogs , "in" ): {
765+ Receivers : []component.ID {component .NewID (nopType )},
766+ Processors : []component.ID {},
767+ Exporters : []component.ID {component .NewIDWithName (nopType , "connector1" )},
768+ },
769+ pipeline .NewIDWithName (pipeline .SignalLogs , "out" ): {
770+ Receivers : []component.ID {component .NewIDWithName (nopType , "connector1" )},
771+ Processors : []component.ID {},
772+ Exporters : []component.ID {component .NewID (nopType )},
773+ },
774+ },
775+ expectedError : "" ,
776+ },
777+ "Valid without Connector" : {
778+ receiverCfg : map [component.ID ]component.Config {
779+ component .NewID (nopType ): & struct {}{},
780+ },
781+ exporterCfg : map [component.ID ]component.Config {
782+ component .NewID (nopType ): & struct {}{},
783+ },
784+ pipelinesCfg : pipelines.Config {
785+ pipeline .NewIDWithName (pipeline .SignalLogs , "in" ): {
786+ Receivers : []component.ID {component .NewID (nopType )},
787+ Processors : []component.ID {},
788+ Exporters : []component.ID {component .NewID (nopType )},
789+ },
790+ pipeline .NewIDWithName (pipeline .SignalLogs , "out" ): {
791+ Receivers : []component.ID {component .NewID (nopType )},
792+ Processors : []component.ID {},
793+ Exporters : []component.ID {component .NewID (nopType )},
794+ },
795+ },
796+ expectedError : "" ,
797+ },
751798 "Connector used as exporter but not as receiver" : {
752799 connectorCfg : map [component.ID ]component.Config {
753800 component .NewIDWithName (nopType , "connector1" ): & struct {}{},
754801 },
802+ receiverCfg : map [component.ID ]component.Config {
803+ component .NewID (nopType ): & struct {}{},
804+ },
805+ exporterCfg : map [component.ID ]component.Config {
806+ component .NewID (nopType ): & struct {}{},
807+ },
755808 pipelinesCfg : pipelines.Config {
756809 pipeline .NewIDWithName (pipeline .SignalLogs , "in1" ): {
757810 Receivers : []component.ID {component .NewID (nopType )},
@@ -775,6 +828,12 @@ func TestValidateGraph(t *testing.T) {
775828 connectorCfg : map [component.ID ]component.Config {
776829 component .NewIDWithName (nopType , "connector1" ): & struct {}{},
777830 },
831+ receiverCfg : map [component.ID ]component.Config {
832+ component .NewID (nopType ): & struct {}{},
833+ },
834+ exporterCfg : map [component.ID ]component.Config {
835+ component .NewID (nopType ): & struct {}{},
836+ },
778837 pipelinesCfg : pipelines.Config {
779838 pipeline .NewIDWithName (pipeline .SignalLogs , "in1" ): {
780839 Receivers : []component.ID {component .NewID (nopType )},
@@ -794,23 +853,57 @@ func TestValidateGraph(t *testing.T) {
794853 },
795854 expectedError : `failed to build pipelines: connector "nop/connector1" used as receiver in [logs/in2] pipeline but not used in any supported exporter pipeline` ,
796855 },
856+ "Connector creates direct cycle between pipelines" : {
857+ connectorCfg : map [component.ID ]component.Config {
858+ component .NewIDWithName (nopType , "forward" ): & struct {}{},
859+ },
860+ receiverCfg : map [component.ID ]component.Config {
861+ component .NewID (nopType ): & struct {}{},
862+ },
863+ exporterCfg : map [component.ID ]component.Config {
864+ component .NewID (nopType ): & struct {}{},
865+ },
866+ pipelinesCfg : pipelines.Config {
867+ pipeline .NewIDWithName (pipeline .SignalTraces , "in" ): {
868+ Receivers : []component.ID {component .NewIDWithName (nopType , "forward" )},
869+ Processors : []component.ID {},
870+ Exporters : []component.ID {component .NewIDWithName (nopType , "forward" )},
871+ },
872+ pipeline .NewIDWithName (pipeline .SignalTraces , "out" ): {
873+ Receivers : []component.ID {component .NewIDWithName (nopType , "forward" )},
874+ Processors : []component.ID {},
875+ Exporters : []component.ID {component .NewIDWithName (nopType , "forward" )},
876+ },
877+ },
878+ expectedError : `failed to build pipelines: cycle detected: connector "nop/forward" (traces to traces) -> connector "nop/forward" (traces to traces)` ,
879+ },
797880 }
798881
799882 _ , connectorsFactories := builders .NewNopConnectorConfigsAndFactories ()
883+ _ , receiversFactories := builders .NewNopReceiverConfigsAndFactories ()
884+ _ , exportersFactories := builders .NewNopExporterConfigsAndFactories ()
800885
801886 for name , tc := range testCases {
802887 t .Run (name , func (t * testing.T ) {
803888 settings := Settings {
804889 ConnectorsConfigs : tc .connectorCfg ,
805890 ConnectorsFactories : connectorsFactories ,
891+ ReceiversConfigs : tc .receiverCfg ,
892+ ReceiversFactories : receiversFactories ,
893+ ExportersConfigs : tc .exporterCfg ,
894+ ExportersFactories : exportersFactories ,
806895 }
807896 cfg := Config {
808897 Pipelines : tc .pipelinesCfg ,
809898 }
810899
811900 err := ValidateGraph (context .Background (), settings , cfg )
812- require .Error (t , err )
813- assert .Equal (t , tc .expectedError , err .Error ())
901+ if tc .expectedError == "" {
902+ require .NoError (t , err )
903+ } else {
904+ require .Error (t , err )
905+ assert .Equal (t , tc .expectedError , err .Error ())
906+ }
814907 })
815908 }
816909}
0 commit comments