Add some conifguration and logging for the hub
This commit is contained in:
66
registrar/internal/persistence/fake_repo.go
Normal file
66
registrar/internal/persistence/fake_repo.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
svc "go.fixergrid.net/servicedemon/registrar/internal/services"
|
||||
)
|
||||
|
||||
type FakeRepo struct {
|
||||
apps []*svc.Application
|
||||
}
|
||||
|
||||
func NewFakeRepo() *FakeRepo {
|
||||
return &FakeRepo{
|
||||
apps: make([]*svc.Application, 0),
|
||||
}
|
||||
}
|
||||
func (repo FakeRepo) IsRegistered(name string) bool {
|
||||
for _, app := range repo.apps {
|
||||
if name == app.Name && app.State == "registered" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (repo FakeRepo) GetApp(name string) (svc.Application, error) {
|
||||
for _, app := range repo.apps {
|
||||
if name == app.Name {
|
||||
return *app, nil
|
||||
}
|
||||
}
|
||||
|
||||
return svc.Application{}, svc.ErrApplicationNotFound
|
||||
}
|
||||
|
||||
func (repo FakeRepo) PendingApprovalCount() int {
|
||||
count := 0
|
||||
for _, app := range repo.apps {
|
||||
if app.State == "pending_approval" {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (repo *FakeRepo) StartAppRegistration(name string) uuid.UUID {
|
||||
newApp := &svc.Application{
|
||||
ID: uuid.New(),
|
||||
Name: name,
|
||||
State: "pending_approval",
|
||||
}
|
||||
repo.apps = append(repo.apps, newApp)
|
||||
return newApp.ID
|
||||
}
|
||||
|
||||
func (repo *FakeRepo) ApproveApp(id uuid.UUID) (svc.Application, error) {
|
||||
for _, application := range repo.apps {
|
||||
if application.ID == id {
|
||||
application.State = "registered"
|
||||
return *application, nil
|
||||
}
|
||||
}
|
||||
|
||||
return svc.Application{}, svc.ErrApplicationNotFound
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user