diff --git a/service/collector.go b/service/collector.go index ace363a84ca..6f84b98eb1c 100644 --- a/service/collector.go +++ b/service/collector.go @@ -50,6 +50,20 @@ const ( Closed ) +func (s State) String() string { + switch s { + case Starting: + return "Starting" + case Running: + return "Running" + case Closing: + return "Closing" + case Closed: + return "Closed" + } + return "" +} + // (Internal note) Collector Lifecycle: // - New constructs a new Collector. // - Run starts the collector. diff --git a/service/collector_test.go b/service/collector_test.go index 27a80f1bb1d..7f9daeaa2a7 100644 --- a/service/collector_test.go +++ b/service/collector_test.go @@ -40,6 +40,13 @@ import ( "go.opentelemetry.io/collector/internal/testutil" ) +func TestStateString(t *testing.T) { + assert.Equal(t, "Starting", Starting.String()) + assert.Equal(t, "Running", Running.String()) + assert.Equal(t, "Closing", Closing.String()) + assert.Equal(t, "Closed", Closed.String()) +} + // TestCollector_StartAsGoRoutine must be the first unit test on the file, // to test for initialization without setting CLI flags. func TestCollector_StartAsGoRoutine(t *testing.T) {