From f1654ba6bd9c603692bf8637120204d7aa55f34d Mon Sep 17 00:00:00 2001 From: gi8 Date: Thu, 23 Jan 2025 19:37:48 +0100 Subject: [PATCH] enum: use other type for unsupported check type --- internal/checker/checker.go | 14 +++++++------- internal/checker/checker_test.go | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 968e1b8..abd2dcf 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -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. @@ -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) } } @@ -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) } } diff --git a/internal/checker/checker_test.go b/internal/checker/checker_test.go index 80f7903..ae43e5c 100644 --- a/internal/checker/checker_test.go +++ b/internal/checker/checker_test.go @@ -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: ") }) }