diff --git a/service/site.go b/service/site.go index bffb5f5..7c2f313 100644 --- a/service/site.go +++ b/service/site.go @@ -6,6 +6,7 @@ import ( "net/url" "github.com/sprak3000/go-glitch/glitch" + whatsupstatus "github.com/sprak3000/go-whatsup-client/status" "github.com/sprak3000/go-whatsup-client/whatsup" "github.com/sprak3000/xbar-whats-up/configuration" @@ -22,7 +23,7 @@ const ( // Reader provides the requirements for anyone implementing reading a service's status type Reader interface { - ReadStatus(client whatsup.StatusPageClient) (status.Details, glitch.DataError) + ReadStatus(client whatsup.StatusPageClient) (whatsupstatus.Details, glitch.DataError) } // Site holds the data for service status pages @@ -64,7 +65,7 @@ type Sites map[string]Site func (sites Sites) GetOverview(client whatsup.StatusPageClient) status.Overview { overview := status.Overview{ OverallStatus: "none", - List: map[string][]status.Details{}, + List: map[string][]whatsupstatus.Details{}, Errors: []string{}, } diff --git a/service/site_test.go b/service/site_test.go index 11effe0..c840010 100644 --- a/service/site_test.go +++ b/service/site_test.go @@ -6,6 +6,7 @@ import ( "io/fs" "net/url" "testing" + "time" "github.com/golang/mock/gomock" "github.com/sprak3000/go-glitch/glitch" @@ -15,6 +16,7 @@ import ( "github.com/stretchr/testify/require" "github.com/sprak3000/xbar-whats-up/configuration" + "github.com/sprak3000/xbar-whats-up/slack" "github.com/sprak3000/xbar-whats-up/status" "github.com/sprak3000/xbar-whats-up/statuspageio" ) @@ -116,6 +118,16 @@ func TestUnit_GetOverview(t *testing.T) { }, } + slackURL, err := url.Parse("https://status.slack.com/api/v2.0.0/current") + require.NoError(t, err) + + slackNoOutageResp := slack.Response{ + Status: "none", + DateCreated: time.Time{}, + DateUpdated: time.Time{}, + ActiveIncidents: nil, + } + tests := map[string]struct { sites Sites setupStatusPageClient func(t *testing.T, expectedErr glitch.DataError) whatsup.StatusPageClient @@ -133,23 +145,31 @@ func TestUnit_GetOverview(t *testing.T) { URL: *circleciURL, Type: statuspageio.ServiceType, }, + "Slack": { + URL: *slackURL, + Type: slack.ServiceType, + }, }, setupStatusPageClient: func(t *testing.T, expectedErr glitch.DataError) whatsup.StatusPageClient { c := clientmock.NewMockStatusPageClient(ctrl) c.EXPECT().StatuspageIoService("CodeClimate", codeClimateURL.String()).Times(1).Return(codeClimateMinorOutageResp, nil) c.EXPECT().StatuspageIoService("CircleCI", circleciURL.String()).Times(1).Return(circleciMajorOutageResp, nil) + c.EXPECT().Slack().Times(1).Return(slackNoOutageResp, nil) return c }, expectedOverview: status.Overview{ OverallStatus: "major", LargestStringSize: 11, - List: map[string][]status.Details{ + List: map[string][]whatsupstatus.Details{ "major": { circleciMajorOutageResp, }, "minor": { codeClimateMinorOutageResp, }, + "none": { + slackNoOutageResp, + }, }, Errors: []string{}, }, @@ -177,7 +197,7 @@ func TestUnit_GetOverview(t *testing.T) { expectedOverview: status.Overview{ OverallStatus: "minor", LargestStringSize: 11, - List: map[string][]status.Details{ + List: map[string][]whatsupstatus.Details{ "minor": { circleciMinorOutageResp, }, @@ -211,7 +231,7 @@ func TestUnit_GetOverview(t *testing.T) { expectedOverview: status.Overview{ OverallStatus: "none", LargestStringSize: 11, - List: map[string][]status.Details{ + List: map[string][]whatsupstatus.Details{ "none": { statuspageio.Response{ Page: statuspageio.Page{ @@ -247,7 +267,7 @@ func TestUnit_GetOverview(t *testing.T) { }, expectedOverview: status.Overview{ OverallStatus: "none", - List: map[string][]status.Details{}, + List: map[string][]whatsupstatus.Details{}, Errors: []string{ "CodeClimate uses an unsupported service type not-a-finger", }, diff --git a/slack/response.go b/slack/response.go index 07e228b..ca12388 100644 --- a/slack/response.go +++ b/slack/response.go @@ -5,9 +5,8 @@ import ( "time" "github.com/sprak3000/go-glitch/glitch" + whatsupstatus "github.com/sprak3000/go-whatsup-client/status" "github.com/sprak3000/go-whatsup-client/whatsup" - - "github.com/sprak3000/xbar-whats-up/status" ) // ServiceType is the name we use for various checks @@ -37,7 +36,7 @@ type ClientReader struct { } // ReadStatus handles communicating with the service to get its status details -func (cr ClientReader) ReadStatus(client whatsup.StatusPageClient) (status.Details, glitch.DataError) { +func (cr ClientReader) ReadStatus(client whatsup.StatusPageClient) (whatsupstatus.Details, glitch.DataError) { return client.Slack() } diff --git a/status/details.go b/status/details.go deleted file mode 100644 index e2270ab..0000000 --- a/status/details.go +++ /dev/null @@ -1,14 +0,0 @@ -// Package status is an abstraction for handling and displaying status details from various services -package status - -import ( - "time" -) - -// Details provides an interface for extracting information from a service's status response -type Details interface { - Indicator() string - Name() string - UpdatedAt() time.Time - URL() string -} diff --git a/status/overview.go b/status/overview.go index 15157da..729b4ec 100644 --- a/status/overview.go +++ b/status/overview.go @@ -4,10 +4,12 @@ package status import ( "fmt" "io" + + whatsupstatus "github.com/sprak3000/go-whatsup-client/status" ) // List is a mapping of status codes to services reporting that status code -type List map[string][]Details +type List map[string][]whatsupstatus.Details // Overview provides an overall status for all services monitored -- most severe status wins -- along with all the // services categorized by status @@ -41,7 +43,7 @@ func (o Overview) Display(w io.Writer) { } } -func displayDetails(w io.Writer, largestStringSize int, details []Details, detailColor string) { +func displayDetails(w io.Writer, largestStringSize int, details []whatsupstatus.Details, detailColor string) { _, _ = fmt.Fprintln(w, "---") if len(details) > 0 { for _, v := range details { diff --git a/status/overview_test.go b/status/overview_test.go index 2b088ee..0af9842 100644 --- a/status/overview_test.go +++ b/status/overview_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + whatsupstatus "github.com/sprak3000/go-whatsup-client/status" "github.com/stretchr/testify/require" ) @@ -22,7 +23,7 @@ func TestUnit_Overview_Display(t *testing.T) { o := Overview{ OverallStatus: "major", LargestStringSize: 12, - List: map[string][]Details{ + List: map[string][]whatsupstatus.Details{ "major": { testResponse{ updatedAt: now, @@ -52,7 +53,7 @@ func TestUnit_Overview_Display(t *testing.T) { o := Overview{ OverallStatus: "minor", LargestStringSize: 12, - List: map[string][]Details{ + List: map[string][]whatsupstatus.Details{ "minor": { testResponse{ updatedAt: now, @@ -77,7 +78,7 @@ func TestUnit_Overview_Display(t *testing.T) { o := Overview{ OverallStatus: "none", LargestStringSize: 12, - List: map[string][]Details{ + List: map[string][]whatsupstatus.Details{ "none": { testResponse{ updatedAt: now, @@ -97,7 +98,7 @@ func TestUnit_Overview_Display(t *testing.T) { o := Overview{ OverallStatus: "none", LargestStringSize: 12, - List: map[string][]Details{ + List: map[string][]whatsupstatus.Details{ "none": { testResponse{ updatedAt: now, diff --git a/statuspageio/response.go b/statuspageio/response.go index e1c4f90..84239dc 100644 --- a/statuspageio/response.go +++ b/statuspageio/response.go @@ -5,9 +5,8 @@ import ( "time" "github.com/sprak3000/go-glitch/glitch" + whatsupstatus "github.com/sprak3000/go-whatsup-client/status" "github.com/sprak3000/go-whatsup-client/whatsup" - - "github.com/sprak3000/xbar-whats-up/status" ) // ServiceType is the name we use for various checks @@ -35,7 +34,7 @@ type ClientReader struct { } // ReadStatus handles communicating with the service to get its status details -func (cr ClientReader) ReadStatus(client whatsup.StatusPageClient) (status.Details, glitch.DataError) { +func (cr ClientReader) ReadStatus(client whatsup.StatusPageClient) (whatsupstatus.Details, glitch.DataError) { return client.StatuspageIoService(cr.ServiceName, cr.PageURL) }