1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-mock.git synced 2024-12-27 05:36:42 +00:00

Additional changes to allow better testability

This commit is contained in:
diamondburned (Forefront) 2020-05-29 11:41:40 -07:00
parent bc9f49c387
commit 47fa2491d2
2 changed files with 17 additions and 6 deletions

View file

@ -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

View file

@ -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