From 29af400745669cf1f5a33ebf00e0e5dc89f1be6b Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Fri, 31 Jan 2020 08:18:38 +0100 Subject: [PATCH] Fix targets generator --- benchmarks/.gitignore | 1 + benchmarks/gen_targets.go | 22 ++++++++++++++-------- benchmarks/templates/responses.tpl | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/benchmarks/.gitignore b/benchmarks/.gitignore index 57d1f604..bd8634c2 100644 --- a/benchmarks/.gitignore +++ b/benchmarks/.gitignore @@ -1,2 +1,3 @@ benchmarks targets/* +results/* diff --git a/benchmarks/gen_targets.go b/benchmarks/gen_targets.go index 2c39383e..66d9996a 100644 --- a/benchmarks/gen_targets.go +++ b/benchmarks/gen_targets.go @@ -7,9 +7,11 @@ import ( "log" "os" "path" + "path/filepath" "strings" "text/template" + "git.andreafazzi.eu/andrea/oef/client" "git.andreafazzi.eu/andrea/oef/orm" "github.com/gocarina/gocsv" ) @@ -44,22 +46,26 @@ func genResponseTargets(targetName string) error { log.Println("Obtaining tokens for each participants...") data.Tokens = make(map[string]string, 0) - // for _, participant := range data.Participants { - // token, err := client.GetToken(url, participant.FiscalCode, participant.Password) - // if err != nil { - // return err - // } - // data.Tokens[participant.FiscalCode] = token - // } + for _, participant := range data.Participants { + token, err := client.GetToken(url, participant.FiscalCode, participant.Password) + if err != nil { + return err + } + data.Tokens[participant.FiscalCode] = token + } tmplPath := path.Join(templateDir, targetName+".tpl") log.Printf("Parse %s template", tmplPath) - tmpl, err := template.New(tmplPath).Funcs(template.FuncMap{"incr": incr}).ParseFiles(tmplPath) + tmpl, err := template.New(filepath.Base(tmplPath)).Funcs(template.FuncMap{"incr": incr}).ParseFiles(tmplPath) if err != nil { return err } + err = os.Mkdir("targets", 0777) + if errors.Is(err, &os.PathError{}) { + return err + } output, err := os.Create("./targets/response_targets.txt") if err != nil { return err diff --git a/benchmarks/templates/responses.tpl b/benchmarks/templates/responses.tpl index 877a9e77..4e2260fd 100644 --- a/benchmarks/templates/responses.tpl +++ b/benchmarks/templates/responses.tpl @@ -1,4 +1,4 @@ {{range $id, $participant := .Participants -}} {{- $username := $participant.FiscalCode -}} -GET https://test.olimpiadi-economiaefinanza.it/responses/{{$id|incr}}?format=html&tpl_content=responses_show&tpl_layout=base&login_session={{index $.Tokens $username}} +GET https://test.olimpiadi-economiaefinanza.it/responses/{{$id|incr}}/update?format=html&tpl_content=responses_add_update&tpl_layout=base&update=true&login_session={{index $.Tokens $username}} {{end}}