| 15 | ) |
| 16 | |
| 17 | func TestCmdRoot(t *testing.T) { |
| 18 | t.Run("root", func(t *testing.T) { |
| 19 | cmdtest.TestHelp(t, cli.CmdRoot) |
| 20 | }) |
| 21 | |
| 22 | t.Run("--help", func(t *testing.T) { |
| 23 | cmdtest.TestHelp(t, cli.CmdRoot, "--help") |
| 24 | }) |
| 25 | |
| 26 | // config |
| 27 | |
| 28 | tests := []struct { |
| 29 | name string |
| 30 | |
| 31 | argv []string |
| 32 | env map[string]string |
| 33 | |
| 34 | want any |
| 35 | get func(*cli.Config) any |
| 36 | }{ |
| 37 | // dashboard url |
| 38 | { |
| 39 | name: "default-dashboard-url", |
| 40 | |
| 41 | want: "https://anchor.dev", |
| 42 | get: func(cli *cli.Config) any { return cli.Dashboard.URL }, |
| 43 | }, |
| 44 | { |
| 45 | name: "--dashboard-url", |
| 46 | |
| 47 | argv: []string{"--dashboard-url", "https://anchor.example.com"}, |
| 48 | |
| 49 | want: "https://anchor.example.com", |
| 50 | get: func(cli *cli.Config) any { return cli.Dashboard.URL }, |
| 51 | }, |
| 52 | { |
| 53 | name: "ANCHOR_HOST", |
| 54 | |
| 55 | env: map[string]string{"ANCHOR_HOST": "https://anchor.example.com"}, |
| 56 | |
| 57 | want: "https://anchor.example.com", |
| 58 | get: func(cli *cli.Config) any { return cli.Dashboard.URL }, |
| 59 | }, |
| 60 | |
| 61 | // api url |
| 62 | { |
| 63 | name: "default-api-url", |
| 64 | |
| 65 | want: "https://api.anchor.dev/v0", |
| 66 | get: func(cli *cli.Config) any { return cli.API.URL }, |
| 67 | }, |
| 68 | { |
| 69 | name: "--api-url", |
| 70 | |
| 71 | argv: []string{"--api-url", "https://api.anchor.example.com"}, |
| 72 | |
| 73 | want: "https://api.anchor.example.com", |
| 74 | get: func(cli *cli.Config) any { return cli.API.URL }, |