cmdExport writes everything needed to check a result to a folder or archive: each run's command, output and report, every request with the response gh got, the stored responses, and the schema files the checks used.
(args []string, stdout io.Writer)
| 45 | // run's command, output and report, every request with the response gh got, |
| 46 | // the stored responses, and the schema files the checks used. |
| 47 | func cmdExport(args []string, stdout io.Writer) error { |
| 48 | opts, err := parseExportArgs(args) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | st, err := openState() |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | runs, err := st.readRuns() |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | if len(runs) == 0 { |
| 61 | return errors.New("nothing to export yet; run gh with ghmock run first") |
| 62 | } |
| 63 | entries, err := st.readLog() |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | responses, err := st.loadResponses() |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | write := func(dir string) error { |
| 72 | return writeExportDir(st, dir, runs, entries, responses) |
| 73 | } |
| 74 | if opts.archive { |
| 75 | err = writeExportArchive(opts.path, write) |
| 76 | } else { |
| 77 | err = write(opts.path) |
| 78 | } |
| 79 | if err != nil { |
| 80 | return err |
| 81 | } |
| 82 | |
| 83 | total, offSchema := 0, 0 |
| 84 | for _, list := range responses { |
| 85 | for _, r := range list { |
| 86 | total++ |
| 87 | if r.OffSchema { |
| 88 | offSchema++ |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | summary := fmt.Sprintf("Exported %s, %s and %s", plural(len(runs), "run"), plural(len(entries), "request"), plural(total, "response")) |
| 93 | if offSchema > 0 { |
| 94 | summary += fmt.Sprintf(", %d off-schema,", offSchema) |
| 95 | } |
| 96 | fmt.Fprintf(stdout, "%s to %s\n", summary, opts.path) |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | func writeExportDir(st *state, dir string, runs []runRecord, entries []loggedRequest, responses responseSet) error { |
| 101 | if err := prepareExportDir(dir); err != nil { |