-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test suite, made changes according to review
- Loading branch information
Showing
12 changed files
with
121 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package model | ||
|
||
import "database/sql" | ||
|
||
type Database struct { | ||
DB *sql.DB | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package model | ||
|
||
type StatusPage struct { | ||
Name string | ||
URL string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,46 @@ | ||
package tests | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"os" | ||
"testing" | ||
model "web/model" | ||
httpTemplates "web/views/templates" | ||
|
||
"github.com/jarcoal/httpmock" | ||
"github.com/joho/godotenv" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
func TestStatusPageWhenAllServicesDown(tests *testing.T) { | ||
if err := godotenv.Load("../.env.tests"); err != nil { | ||
log.Fatalf("Error loading .env.tests file") | ||
} | ||
|
||
func (suite *StatusPageSuite) TestStatusPageWhenAllServicesDown() { | ||
// Arrange | ||
urlPrefix := "http://" | ||
httpmock.Activate() | ||
defer httpmock.DeactivateAndReset() | ||
|
||
services := []model.ServiceStatusInfo{ | ||
services := []model.StatusPage{ | ||
{ | ||
Name: "API", | ||
URL: urlPrefix + os.Getenv("APP_HOST") + ":" + os.Getenv("APP_PORT") + os.Getenv("API_PATH") + "ping", | ||
}, | ||
} | ||
|
||
// Act | ||
|
||
// Register mock responders for all service endpoints | ||
for _, service := range services { | ||
httpmock.RegisterResponder("GET", service.URL, httpmock.NewErrorResponder(http.ErrServerClosed)) | ||
} | ||
|
||
statuses := httpTemplates.CheckServicesStatus(services) | ||
|
||
// Assert | ||
// Check the status of all services | ||
for i, service := range services { | ||
assert.Equalf(tests, "down", statuses[i]["status"], "Expected %s status to be down, got %s", service.Name, statuses[i]["status"]) | ||
assert.Equalf(suite.T(), "down", statuses[i]["status"], "expected %s status to be down, got %s", service.Name, statuses[i]["status"]) | ||
} | ||
} | ||
|
||
func WrapTestsIntoSuite(t *testing.T) { | ||
suite.Run(t, new(StatusPageSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package tests | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type StatusPageSuite struct { | ||
suite.Suite | ||
} | ||
|
||
// SetupTest will be run before each test in the suite | ||
func (suite *StatusPageSuite) SetupTestEnvironmentals() { | ||
os.Setenv("APP_PORT", "8000") | ||
os.Setenv("APP_HOST", "localhost") | ||
os.Setenv("DEBUG_MODE", "true") | ||
os.Setenv("API_PATH", "/api/v1/") | ||
os.Setenv("FORCE_TLS", "false") | ||
os.Setenv("PSQL_ENABLED", "false") | ||
os.Setenv("POSTGRES_HOST", "localhost") | ||
os.Setenv("POSTGRES_PORT", "5432") | ||
os.Setenv("POSTGRES_USER", "postgres") | ||
os.Setenv("POSTGRES_PASSWORD", "postgres") | ||
os.Setenv("POSTGRES_DB", "postgres") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
.container { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
} | ||
|
||
.status { | ||
text-align: center; | ||
font-size: 24px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.service { | ||
margin-bottom: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters