func testStorage(t *testing.T, s common.Storage, lpath, rpath string, files []testFile) { for _, file := range files { err := s.Put(file.name) if err != nil { t.Error(err) } lfile := path.Join(lpath, file.name) rfile := path.Join(rpath, file.name) same, err := compareFiles(lfile, rfile) if err != nil { t.Error(err) } if !same { t.Errorf("files '%v' and '%v' did not match", lfile, rfile) } } }
func runCommands(t *testing.T, s common.Storage, cmds []interface{}) { for _, cmd := range cmds { var err error switch cmd := cmd.(type) { case common.GetMsg: err = s.Get(cmd.Id) case common.PutMsg: err = s.Put(cmd.Id) case common.DelMsg: err = s.Delete(cmd.Id) default: t.Fatal("unrecognized command") } if err != nil { t.Fatalf("command '%v' failed: %v", cmd, err) } } }