Skip to content

Commit

Permalink
Implement Stringer for service.State
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Mar 1, 2022
1 parent 73a30a6 commit 58f0b17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions service/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 58f0b17

Please sign in to comment.