()
| 34 | } |
| 35 | |
| 36 | func (r *RootCmd) speedtest() *serpent.Command { |
| 37 | var ( |
| 38 | direct bool |
| 39 | duration time.Duration |
| 40 | direction string |
| 41 | pcapFile string |
| 42 | formatter = cliui.NewOutputFormatter( |
| 43 | cliui.ChangeFormatterData(cliui.TableFormat([]speedtestTableItem{}, []string{"Interval", "Throughput"}), func(data any) (any, error) { |
| 44 | res, ok := data.(SpeedtestResult) |
| 45 | if !ok { |
| 46 | // This should never happen |
| 47 | return "", xerrors.Errorf("expected speedtestResult, got %T", data) |
| 48 | } |
| 49 | tableRows := make([]any, len(res.Intervals)+2) |
| 50 | for i, r := range res.Intervals { |
| 51 | tableRows[i] = speedtestTableItem{ |
| 52 | Interval: fmt.Sprintf("%.2f-%.2f sec", r.StartTimeSeconds, r.EndTimeSeconds), |
| 53 | Throughput: fmt.Sprintf("%.4f Mbits/sec", r.ThroughputMbits), |
| 54 | } |
| 55 | } |
| 56 | tableRows[len(res.Intervals)] = cliui.TableSeparator{} |
| 57 | tableRows[len(res.Intervals)+1] = speedtestTableItem{ |
| 58 | Interval: fmt.Sprintf("%.2f-%.2f sec", res.Overall.StartTimeSeconds, res.Overall.EndTimeSeconds), |
| 59 | Throughput: fmt.Sprintf("%.4f Mbits/sec", res.Overall.ThroughputMbits), |
| 60 | } |
| 61 | return tableRows, nil |
| 62 | }), |
| 63 | cliui.JSONFormat(), |
| 64 | ) |
| 65 | ) |
| 66 | cmd := &serpent.Command{ |
| 67 | Annotations: workspaceCommand, |
| 68 | Use: "speedtest <workspace>", |
| 69 | Short: "Run upload and download tests from your machine to a workspace", |
| 70 | Middleware: serpent.Chain( |
| 71 | serpent.RequireNArgs(1), |
| 72 | ), |
| 73 | Handler: func(inv *serpent.Invocation) error { |
| 74 | ctx, cancel := context.WithCancel(inv.Context()) |
| 75 | defer cancel() |
| 76 | client, err := r.InitClient(inv) |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | appearanceConfig := initAppearance(ctx, client) |
| 81 | |
| 82 | if direct && r.disableDirect { |
| 83 | return xerrors.Errorf("--direct (-d) is incompatible with --%s", varDisableDirect) |
| 84 | } |
| 85 | |
| 86 | _, workspaceAgent, _, err := GetWorkspaceAndAgent(ctx, inv, client, false, inv.Args[0]) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | |
| 91 | err = cliui.Agent(ctx, inv.Stderr, workspaceAgent.ID, cliui.AgentOptions{ |
| 92 | Fetch: client.WorkspaceAgent, |
| 93 | Wait: false, |
no test coverage detected