── registerService ──
(t *testing.T)
| 53 | // ── registerService ── |
| 54 | |
| 55 | func TestRegisterService(t *testing.T) { |
| 56 | parent := &cobra.Command{Use: "root"} |
| 57 | f := &cmdutil.Factory{} |
| 58 | base := meta.ServiceFromMap(map[string]interface{}{ |
| 59 | "name": "base", |
| 60 | "description": "Base API", |
| 61 | "servicePath": "/open-apis/base/v3", |
| 62 | "resources": map[string]interface{}{ |
| 63 | "tables": map[string]interface{}{ |
| 64 | "methods": map[string]interface{}{ |
| 65 | "list": map[string]interface{}{ |
| 66 | "description": "List tables", |
| 67 | "httpMethod": "GET", |
| 68 | }, |
| 69 | }, |
| 70 | }, |
| 71 | }, |
| 72 | }) |
| 73 | |
| 74 | registerService(parent, base, f) |
| 75 | |
| 76 | // service command exists |
| 77 | svc, _, err := parent.Find([]string{"base"}) |
| 78 | if err != nil || svc.Name() != "base" { |
| 79 | t.Fatalf("expected 'base' command, got err=%v", err) |
| 80 | } |
| 81 | // resource sub-command |
| 82 | res, _, err := parent.Find([]string{"base", "tables"}) |
| 83 | if err != nil || res.Name() != "tables" { |
| 84 | t.Fatalf("expected 'tables' command, got err=%v", err) |
| 85 | } |
| 86 | // method sub-command |
| 87 | meth, _, err := parent.Find([]string{"base", "tables", "list"}) |
| 88 | if err != nil || meth.Name() != "list" { |
| 89 | t.Fatalf("expected 'list' command, got err=%v", err) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | func TestRegisterService_MergesExistingCommand(t *testing.T) { |
| 94 | parent := &cobra.Command{Use: "root"} |
nothing calls this directly
no test coverage detected