mirror of
https://github.com/diamondburned/cchat-mock.git
synced 2024-12-26 21:27:05 +00:00
Additional changes to allow better testability
This commit is contained in:
parent
bc9f49c387
commit
47fa2491d2
|
@ -104,7 +104,7 @@ func generateChannels(s *Session, amount int) []cchat.Server {
|
|||
|
||||
// emulate network latency
|
||||
func emulateAustralianInternet() (lost bool) {
|
||||
var ms = rand.Intn(internetMaxLatency) + internetMinLatency
|
||||
var ms = rand.Intn(internetMaxLatency-internetMinLatency) + internetMinLatency
|
||||
<-time.After(time.Duration(ms) * time.Millisecond)
|
||||
|
||||
// because australia, drop packet 20% of the time if internetCanFail is
|
||||
|
|
19
service.go
19
service.go
|
@ -47,9 +47,19 @@ type Authenticator struct{}
|
|||
var _ cchat.Authenticator = (*Authenticator)(nil)
|
||||
|
||||
func (Authenticator) AuthenticateForm() []cchat.AuthenticateEntry {
|
||||
return []cchat.AuthenticateEntry{{
|
||||
return []cchat.AuthenticateEntry{
|
||||
{
|
||||
Name: "Username",
|
||||
}}
|
||||
},
|
||||
{
|
||||
Name: "Password (ignored)",
|
||||
Secret: true,
|
||||
},
|
||||
{
|
||||
Name: "Paragraph (ignored)",
|
||||
Multiline: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (Authenticator) Authenticate(form []string) (cchat.Session, error) {
|
||||
|
@ -61,7 +71,7 @@ var (
|
|||
internetCanFail = true
|
||||
// 500ms ~ 3s
|
||||
internetMinLatency = 500
|
||||
internetMaxLatency = 2500
|
||||
internetMaxLatency = 3000
|
||||
)
|
||||
|
||||
func (s Service) Configuration() (map[string]string, error) {
|
||||
|
@ -90,7 +100,8 @@ func (s Service) SetConfiguration(config map[string]string) error {
|
|||
func unmarshalConfig(config map[string]string, key string, value interface{}) error {
|
||||
if err := json.Unmarshal([]byte(config[key]), value); err != nil {
|
||||
return &cchat.ErrInvalidConfigAtField{
|
||||
Key: key, Err: err,
|
||||
Key: key,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue