-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from eurofurence/issue-33-flesh-out
Issue 33 flesh out
- Loading branch information
Showing
46 changed files
with
656 additions
and
550 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package config | ||
|
||
func (c *Config) AddDefaults() { | ||
if c.Server.Port == 0 { | ||
c.Server.Port = 8081 | ||
} | ||
} |
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,23 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
aulogging "github.com/StephanHCB/go-autumn-logging" | ||
) | ||
|
||
func (c *Config) Validate() error { | ||
ok := true | ||
|
||
if c.Server.Port <= 1024 || c.Server.Port > 65535 { | ||
aulogging.Logger.NoCtx().Warn().Print("server.port out of range") | ||
ok = false | ||
} | ||
|
||
// TODO more validation | ||
|
||
if ok { | ||
return nil | ||
} else { | ||
return errors.New("configuration validation error, see log output for details") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package attendeeservice | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/eurofurence/reg-room-service/internal/repository/downstreams" | ||
"github.com/eurofurence/reg-room-service/internal/web/common" | ||
) | ||
|
||
type Mock interface { | ||
AttendeeService | ||
|
||
Reset() | ||
Unavailable() | ||
SetupRegistered(subject string, badgeNo int64, status Status) | ||
} | ||
|
||
type MockImpl struct { | ||
IdsBySubject map[string][]int64 | ||
StatusById map[int64]Status | ||
IsUnavailable bool | ||
} | ||
|
||
func NewMock() Mock { | ||
instance := &MockImpl{} | ||
instance.Reset() | ||
return instance | ||
} | ||
|
||
func (m *MockImpl) ListMyRegistrationIds(ctx context.Context) ([]int64, error) { | ||
if m.IsUnavailable { | ||
return make([]int64, 0), downstreams.ErrDownStreamUnavailable | ||
} | ||
|
||
claimsPtr := ctx.Value(common.CtxKeyClaims{}) | ||
if claimsPtr == nil { | ||
// no auth -> no badge numbers, but also not an error | ||
return make([]int64, 0), nil | ||
} | ||
claims, ok := claimsPtr.(*common.AllClaims) | ||
if !ok { | ||
return make([]int64, 0), errors.New("internal error - found invalid data type in context - this indicates a bug") | ||
} | ||
|
||
subject := claims.Subject | ||
if subject == "" { | ||
return make([]int64, 0), errors.New("invalid authentication in context, lacks subject - probably indicates a bug") | ||
} | ||
|
||
ids, ok := m.IdsBySubject[subject] | ||
if !ok { | ||
// not known -> no badge numbers, but also not an error | ||
return make([]int64, 0), nil | ||
} | ||
|
||
return ids, nil | ||
} | ||
|
||
func (m *MockImpl) GetStatus(ctx context.Context, id int64) (Status, error) { | ||
if m.IsUnavailable { | ||
return StatusDeleted, downstreams.ErrDownStreamUnavailable | ||
} | ||
|
||
status, ok := m.StatusById[id] | ||
if !ok { | ||
return StatusDeleted, nil | ||
} | ||
|
||
return status, nil | ||
} | ||
|
||
func (m *MockImpl) Reset() { | ||
m.IdsBySubject = make(map[string][]int64) | ||
m.StatusById = make(map[int64]Status) | ||
m.IsUnavailable = false | ||
} | ||
|
||
func (m *MockImpl) Unavailable() { | ||
m.IsUnavailable = true | ||
} | ||
|
||
func (m *MockImpl) SetupRegistered(subject string, badgeNo int64, status Status) { | ||
m.IdsBySubject[subject] = []int64{badgeNo} | ||
m.StatusById[badgeNo] = status | ||
} |
Oops, something went wrong.