This commit is contained in:
Neale Pickett 2019-12-01 20:53:13 -07:00
parent 5dccc6431d
commit 97da227777
2 changed files with 26 additions and 26 deletions

View File

@ -116,20 +116,20 @@ func (s *State) TeamName(teamId string) (string, error) {
// Write out team name. This can only be done once.
func (s *State) SetTeamName(teamId string, teamName string) error {
if f, err := s.fs.Open("teamids.txt"); err != nil {
return fmt.Errorf("Team IDs file does not exist")
return fmt.Errorf("Team IDs file does not exist")
} else {
ok := false
scanner := bufio.NewScanner(f)
for scanner.Scan() {
if scanner.Text() == teamId {
ok = true
break
}
}
f.Close()
if !ok {
return fmt.Errorf("Team ID not found in list of valid Team IDs")
}
found := false
scanner := bufio.NewScanner(f)
for scanner.Scan() {
if scanner.Text() == teamId {
found = true
break
}
}
f.Close()
if !found {
return fmt.Errorf("Team ID not found in list of valid Team IDs")
}
}
teamFile := filepath.Join("teams", teamId)

View File

@ -1,7 +1,7 @@
package main
import (
"bytes"
"bytes"
"github.com/spf13/afero"
"os"
"testing"
@ -20,31 +20,31 @@ func TestState(t *testing.T) {
s := NewState(fs)
s.Cleanup()
pl := s.PointsLog()
if len(pl) != 0 {
t.Errorf("Empty points log is not empty")
}
pl := s.PointsLog()
if len(pl) != 0 {
t.Errorf("Empty points log is not empty")
}
mustExist("initialized")
mustExist("enabled")
mustExist("hours")
teamidsBuf, err := afero.ReadFile(fs, "teamids.txt")
if err != nil {
t.Errorf("Reading teamids.txt: %v", err)
t.Errorf("Reading teamids.txt: %v", err)
}
teamids := bytes.Split(teamidsBuf, []byte("\n"))
if (len(teamids) != 101) || (len(teamids[100]) > 0) {
t.Errorf("There weren't 100 teamids, there were %d", len(teamids))
t.Errorf("There weren't 100 teamids, there were %d", len(teamids))
}
myTeam := string(teamids[0])
if err := s.SetTeamName("bad team ID", "bad team name"); err == nil {
t.Errorf("Setting bad team ID didn't raise an error")
t.Errorf("Setting bad team ID didn't raise an error")
}
if err := s.SetTeamName(myTeam, "My Team"); err != nil {
t.Errorf("Setting team name: %v", err)
t.Errorf("Setting team name: %v", err)
}
}