@@ -617,77 +617,109 @@ func TestSupervisorConfiguresCapabilities(t *testing.T) {
617617}
618618
619619func TestSupervisorBootstrapsCollector (t * testing.T ) {
620- agentDescription := atomic.Value {}
620+ tests := []struct {
621+ name string
622+ cfg string
623+ env []string
624+ precheck func (t * testing.T )
625+ }{
626+ {
627+ name : "With service.AllowNoPipelines" ,
628+ cfg : "nocap" ,
629+ },
630+ {
631+ name : "Without service.AllowNoPipelines" ,
632+ cfg : "no_fg" ,
633+ env : []string {
634+ "COLLECTOR_BIN=../../bin/otelcontribcol_" + runtime .GOOS + "_" + runtime .GOARCH ,
635+ },
636+ precheck : func (t * testing.T ) {
637+ if runtime .GOOS == "windows" {
638+ t .Skip ("This test requires a shell script, which may not be supported by Windows" )
639+ }
640+ },
641+ },
642+ }
621643
622- // Load the Supervisor config so we can get the location of
623- // the Collector that will be run.
624- var cfg config.Supervisor
625- cfgFile := getSupervisorConfig (t , "nocap" , map [string ]string {})
626- k := koanf .New ("::" )
627- err := k .Load (file .Provider (cfgFile .Name ()), yaml .Parser ())
628- require .NoError (t , err )
629- err = k .UnmarshalWithConf ("" , & cfg , koanf.UnmarshalConf {
630- Tag : "mapstructure" ,
631- })
632- require .NoError (t , err )
644+ for _ , tt := range tests {
645+ t .Run (tt .name , func (t * testing.T ) {
646+ agentDescription := atomic.Value {}
633647
634- // Get the binary name and version from the Collector binary
635- // using the `components` command that prints a YAML-encoded
636- // map of information about the Collector build. Some of this
637- // information will be used as defaults for the telemetry
638- // attributes.
639- agentPath := cfg .Agent .Executable
640- componentsInfo , err := exec .Command (agentPath , "components" ).Output ()
641- require .NoError (t , err )
642- k = koanf .New ("::" )
643- err = k .Load (rawbytes .Provider (componentsInfo ), yaml .Parser ())
644- require .NoError (t , err )
645- buildinfo := k .StringMap ("buildinfo" )
646- command := buildinfo ["command" ]
647- version := buildinfo ["version" ]
648+ // Load the Supervisor config so we can get the location of
649+ // the Collector that will be run.
650+ var cfg config.Supervisor
651+ cfgFile := getSupervisorConfig (t , tt .cfg , map [string ]string {})
652+ k := koanf .New ("::" )
653+ err := k .Load (file .Provider (cfgFile .Name ()), yaml .Parser ())
654+ require .NoError (t , err )
655+ err = k .UnmarshalWithConf ("" , & cfg , koanf.UnmarshalConf {
656+ Tag : "mapstructure" ,
657+ })
658+ require .NoError (t , err )
648659
649- server := newOpAMPServer (
650- t ,
651- defaultConnectingHandler ,
652- types.ConnectionCallbacks {
653- OnMessage : func (_ context.Context , _ types.Connection , message * protobufs.AgentToServer ) * protobufs.ServerToAgent {
654- if message .AgentDescription != nil {
655- agentDescription .Store (message .AgentDescription )
656- }
660+ // Get the binary name and version from the Collector binary
661+ // using the `components` command that prints a YAML-encoded
662+ // map of information about the Collector build. Some of this
663+ // information will be used as defaults for the telemetry
664+ // attributes.
665+ agentPath := cfg .Agent .Executable
666+ cmd := exec .Command (agentPath , "components" )
667+ for _ , env := range tt .env {
668+ cmd .Env = append (cmd .Env , env )
669+ }
670+ componentsInfo , err := cmd .Output ()
671+ require .NoError (t , err )
672+ k = koanf .New ("::" )
673+ err = k .Load (rawbytes .Provider (componentsInfo ), yaml .Parser ())
674+ require .NoError (t , err )
675+ buildinfo := k .StringMap ("buildinfo" )
676+ command := buildinfo ["command" ]
677+ version := buildinfo ["version" ]
678+
679+ server := newOpAMPServer (
680+ t ,
681+ defaultConnectingHandler ,
682+ types.ConnectionCallbacks {
683+ OnMessage : func (_ context.Context , _ types.Connection , message * protobufs.AgentToServer ) * protobufs.ServerToAgent {
684+ if message .AgentDescription != nil {
685+ agentDescription .Store (message .AgentDescription )
686+ }
657687
658- return & protobufs.ServerToAgent {}
659- },
660- })
688+ return & protobufs.ServerToAgent {}
689+ },
690+ })
661691
662- s := newSupervisor (t , "nocap" , map [string ]string {"url" : server .addr })
692+ s := newSupervisor (t , "nocap" , map [string ]string {"url" : server .addr })
663693
664- require .Nil (t , s .Start ())
665- defer s .Shutdown ()
694+ require .Nil (t , s .Start ())
695+ defer s .Shutdown ()
666696
667- waitForSupervisorConnection (server .supervisorConnected , true )
697+ waitForSupervisorConnection (server .supervisorConnected , true )
668698
669- require .Eventually (t , func () bool {
670- ad , ok := agentDescription .Load ().(* protobufs.AgentDescription )
671- if ! ok {
672- return false
673- }
699+ require .Eventually (t , func () bool {
700+ ad , ok := agentDescription .Load ().(* protobufs.AgentDescription )
701+ if ! ok {
702+ return false
703+ }
674704
675- var agentName , agentVersion string
676- identAttr := ad .IdentifyingAttributes
677- for _ , attr := range identAttr {
678- switch attr .Key {
679- case semconv .AttributeServiceName :
680- agentName = attr .Value .GetStringValue ()
681- case semconv .AttributeServiceVersion :
682- agentVersion = attr .Value .GetStringValue ()
683- }
684- }
705+ var agentName , agentVersion string
706+ identAttr := ad .IdentifyingAttributes
707+ for _ , attr := range identAttr {
708+ switch attr .Key {
709+ case semconv .AttributeServiceName :
710+ agentName = attr .Value .GetStringValue ()
711+ case semconv .AttributeServiceVersion :
712+ agentVersion = attr .Value .GetStringValue ()
713+ }
714+ }
685715
686- // By default the Collector should report its name and version
687- // from the component.BuildInfo struct built into the Collector
688- // binary.
689- return agentName == command && agentVersion == version
690- }, 5 * time .Second , 250 * time .Millisecond )
716+ // By default the Collector should report its name and version
717+ // from the component.BuildInfo struct built into the Collector
718+ // binary.
719+ return agentName == command && agentVersion == version
720+ }, 5 * time .Second , 250 * time .Millisecond )
721+ })
722+ }
691723}
692724
693725func TestSupervisorBootstrapsCollectorAvailableComponents (t * testing.T ) {
0 commit comments