-
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.
[olivercodes] feat(gh-2): updated service tests, readme, pkg structur…
…e, readiness and liveness probes
- Loading branch information
1 parent
aa82eaa
commit 92e1dfe
Showing
13 changed files
with
277 additions
and
83 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
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
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 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,65 @@ | ||
package mock | ||
|
||
import ( | ||
"fmt" | ||
|
||
"twdps.io/lab-api-teams/pkg/domain" | ||
) | ||
|
||
type MockRepository struct { | ||
Teams []domain.Team | ||
} | ||
|
||
func (m *MockRepository) GetTeams() ([]domain.Team, error) { | ||
return m.Teams, nil | ||
} | ||
|
||
func (m *MockRepository) AddTeam(newTeam domain.Team) error { | ||
m.Teams = append(m.Teams, newTeam) | ||
return nil | ||
} | ||
|
||
func (m *MockRepository) GetTeam(id string) (domain.Team, error) { | ||
for _, team := range m.Teams { | ||
if id == team.TeamID { | ||
return team, nil | ||
} | ||
} | ||
|
||
return domain.Team{}, fmt.Errorf("Team not found") | ||
} | ||
|
||
func update_slice_item(slice []domain.Team, index int, team domain.Team) []domain.Team { | ||
// Remove the index first | ||
teams := append(slice[:index], slice[index+1:]...) | ||
// Update with the new one | ||
return append(teams, team) | ||
} | ||
|
||
func delete_slice_item(slice []domain.Team, index int) []domain.Team { | ||
return append(slice[:index], slice[index+1:]...) | ||
} | ||
|
||
func (m *MockRepository) RemoveTeam(teamID string) error { | ||
for index, team := range m.Teams { | ||
if team.TeamID == teamID { | ||
m.Teams = delete_slice_item(m.Teams, index) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m *MockRepository) UpdateTeam(teamToUpdate domain.Team) error { | ||
for index, team := range m.Teams { | ||
if team.TeamID == teamToUpdate.TeamID { | ||
m.Teams = update_slice_item(m.Teams, index, teamToUpdate) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m *MockRepository) DatabaseAvailable() (bool, error) { | ||
return true, nil | ||
} |
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 mock | ||
|
||
import ( | ||
"testing" | ||
|
||
"twdps.io/lab-api-teams/pkg/domain" | ||
"twdps.io/lab-api-teams/pkg/service" | ||
) | ||
|
||
func TestMock(t *testing.T) { | ||
mockRepository := &MockRepository{ | ||
Teams: []domain.Team{ | ||
{TeamID: "team-sapphire", TeamType: "normal", TeamDescription: "Sapphire frontend team", TeamRAM: 32, TeamCPU: 12, TeamRamLimit: 64, TeamCpuLimit: 24}, | ||
}, | ||
} | ||
|
||
// If Mock Repo didn't implement expected functions this will throw an InvalidIFaceAssign error | ||
// - This is itself a test, albeit it is basically a compiler error test | ||
teamService := service.NewTeamService(mockRepository) | ||
|
||
// Sanity check that mock implements actual functionality. Rest of service tests are in service_test.go | ||
teams, _ := teamService.GetTeams() | ||
if len(teams) != 1 { | ||
t.Errorf("expected %d teams got %d", 1, len(teams)) | ||
} | ||
} |
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
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
Oops, something went wrong.