Skip to content

Commit

Permalink
Issue #47 - Clean out old Details interface
Browse files Browse the repository at this point in the history
- Delete the `status.Details` interface in this repo.
- Convert to use `whatsupstatus.Details` interface instead.
- Small unit test coverage update.
  • Loading branch information
sprak3000 committed Oct 3, 2023
1 parent 8285ee3 commit 6da9673
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 32 deletions.
5 changes: 3 additions & 2 deletions service/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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{},
}

Expand Down
28 changes: 24 additions & 4 deletions service/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/fs"
"net/url"
"testing"
"time"

"github.com/golang/mock/gomock"
"github.com/sprak3000/go-glitch/glitch"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -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{},
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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",
},
Expand Down
5 changes: 2 additions & 3 deletions slack/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down
14 changes: 0 additions & 14 deletions status/details.go

This file was deleted.

6 changes: 4 additions & 2 deletions status/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions status/overview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

whatsupstatus "github.com/sprak3000/go-whatsup-client/status"
"github.com/stretchr/testify/require"
)

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions statuspageio/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 6da9673

Please sign in to comment.