Skip to content

Commit

Permalink
enum: use other type for unsupported check type
Browse files Browse the repository at this point in the history
  • Loading branch information
gi8lino committed Jan 23, 2025
1 parent 827959e commit f1654ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
)

// CheckType represents the type of check to perform.
type CheckType int
type CheckType string

const (
TCP CheckType = iota // TCP represents a check over the TCP protocol.
HTTP // HTTP represents a check over the HTTP protocol.
ICMP // ICMP represents a check using the ICMP protocol (ping).
TCP CheckType = "TCP" // TCP represents a check over the TCP protocol.
HTTP CheckType = "HTTP"
ICMP CheckType = "ICMP"
)

// String returns the string representation of the CheckType.
func (c CheckType) String() string {
return [...]string{"TCP", "HTTP", "ICMP"}[c]
return string(c)
}

// Option defines a functional option for configuring a Checker.
Expand Down Expand Up @@ -59,7 +59,7 @@ func GetCheckTypeFromString(checkTypeStr string) (CheckType, error) {
case "icmp":
return ICMP, nil
default:
return -1, fmt.Errorf("unsupported check type: %s", checkTypeStr)
return "", fmt.Errorf("unsupported check type: %s", checkTypeStr)
}
}

Expand All @@ -74,6 +74,6 @@ func NewChecker(checkType CheckType, name, address string, opts ...Option) (Chec
case ICMP:
return newICMPChecker(name, address, opts...)
default:
return nil, fmt.Errorf("unsupported check type: %d", checkType)
return nil, fmt.Errorf("unsupported check type: %s", checkType)
}
}
4 changes: 2 additions & 2 deletions internal/checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func TestNewChecker(t *testing.T) {
t.Run("Invalid checker type", func(t *testing.T) {
t.Parallel()

_, err := NewChecker(99, "example", "example.com")
_, err := NewChecker("", "example", "example.com")

assert.Error(t, err)
assert.EqualError(t, err, "unsupported check type: 99")
assert.EqualError(t, err, "unsupported check type: ")
})
}

Expand Down

0 comments on commit f1654ba

Please # to comment.