Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate cadl-ranch test to main typespec repo #4015

Open
9 of 12 tasks
timotheeguerin opened this issue Jul 25, 2024 · 2 comments
Open
9 of 12 tasks

Migrate cadl-ranch test to main typespec repo #4015

timotheeguerin opened this issue Jul 25, 2024 · 2 comments
Assignees
Labels
eng feature New feature or request triaged:core

Comments

@timotheeguerin
Copy link
Member

timotheeguerin commented Jul 25, 2024

As part of having the client emitters as well as trying to reuse the specs for service emitters it would be good to have cadl-ranch be directly into typespec

Currently there is a few packages in cadl-ranch:

  • cadl-ranch: Runtime
  • cadl-ranch-expect: Typespec library adding the custom decorators
  • cadl-ranch-api: TS Api to implement the mock api
  • cadl-ranch-dashboard: Website code
  • cadl-ranch-specs: The actual specs

I think we need could move and rename the following:

  • cadl-ranch: Runtime
  • cadl-ranch-expect: Typespec library adding the custom decorators
  • cadl-ranch-api: TS Api to implement the mock api

Then we can migrate the specs expect the azure ones.

The dashboard can remain there for now as it is specific to azure but that will be something that would be very nice to integrate as well

Things to figure out:

  • We need to be able to load multiple scenario set(Split between standard and azure specs)
  • New name?
Category Runtime TSP lib(decorators) Mock api helpers Test specs
Old Name @azure-tools/cadl-ranch @azure-tools/cadl-ranch-expect @azure-tools/cadl-ranch-api @azure-tools/cadl-ranch-specs
-------- ----------------------------- -------------------------------- ----------------------------- -------------------------------
Option 1 @typespec/scenario-director @typespec/scenario-lib @typespec/scenario-api @typespec/http-scenarios
Option 2 @typespec/tsp-cupboard @typespec/tsp-cupboard-lib @typespec/tsp-cupboard-api @typespec/http-tsp-cupboard
Option 3 @typespec/tsp-recipes @typespec/tsp-ingredients @typespec/tsp-recipes-api @typespec/http-recipes
Option 4 @typespec/spec-core @typespec/spec @typespec/spec (we could reuse the same lib) @typespec/rest-spec

Other alternatives:

  • cabinet instead of cupboard for option 2

Steps

Tasks

@markcowl
Copy link
Contributor

est: 8

@timotheeguerin
Copy link
Member Author

timotheeguerin commented Aug 6, 2024

Example what it could look like

function createModelMockApis(route: string, value: any[]): MockApiGetPut {
  const url = `/type/array/${route}`;
  return {
    get: {
      url,
      method: "get",
      request: {},
      repsonse: {
        status: 200,
        body: json(value),
      },
    },
    put: {
      url,
      method: "put",
      request: {
        body: json(value),
      },
      response: {
        status: 204,
      },
    },
  };
}

const Int32ValueMock = createModelMockApis("int32", [1, 2]);
Scenarios.Type_Array_Int32Value_get = passOnSuccess(Int32ValueMock.get);
Scenarios.Type_Array_Int32Value_put = passOnSuccess(Int32ValueMock.put);

Client testing flow

# Start mock server http://localhost:3000
tsp-spec server start ./node_modules/@typespec/rest-spec 

npm run client:test # Run all the emitted client tests - not our problem of what this do

tsp-spec server stop
# upload coverage

Server testing flow

npm run start:server:apis # Start the generated server - not our problem of what this do

# Run mock client tests
tsp-spec client run ./node_modules/@typespec/rest-spec

# upload coverage

Scenarios:

  • 90:
    • api.ts # 2 way format
  • 10%: need both mockapi and mockclient
    • mockapi.ts
    • mockclient.ts

github-merge-queue bot pushed a commit that referenced this issue Sep 17, 2024
#4015

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Timothee Guerin <[email protected]>
Co-authored-by: Timothee Guerin <[email protected]>
Co-authored-by: m-nash <[email protected]>
Co-authored-by: Kyle Zhang <[email protected]>
Co-authored-by: Kyle Zhang <[email protected]>
Co-authored-by: Mario Guerra <[email protected]>
Co-authored-by: Crystal YU <[email protected]>
Co-authored-by: Jorge Rangel <[email protected]>
Co-authored-by: Mark Cowlishaw <[email protected]>
Co-authored-by: Srikanta <[email protected]>
Co-authored-by: Christopher Radek <[email protected]>
Co-authored-by: Christopher Radek <[email protected]>
Co-authored-by: Nisha Bhatia <[email protected]>
Co-authored-by: Wei Hu <[email protected]>
Co-authored-by: iscai-msft <[email protected]>
Co-authored-by: iscai-msft <[email protected]>
Co-authored-by: JoshLove-msft <[email protected]>
Co-authored-by: Dapeng Zhang <[email protected]>
Co-authored-by: Dapeng Zhang <[email protected]>
Co-authored-by: ShivangiReja <[email protected]>
Co-authored-by: ShivangiReja <[email protected]>
Co-authored-by: Mingzhe Huang <[email protected]>
Co-authored-by: Mingzhe Huang (from Dev Box) <[email protected]>
Co-authored-by: Allen Zhang <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Pan Shao <[email protected]>
Co-authored-by: Pan Shao <[email protected]>
Co-authored-by: Weidong Xu <[email protected]>
Co-authored-by: Xiaofei Cao <[email protected]>
Co-authored-by: Alan Zimmer <[email protected]>
Co-authored-by: Alitzel Mendez <[email protected]>
Co-authored-by: Rodge Fu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eng feature New feature or request triaged:core
Projects
None yet
Development

No branches or pull requests

4 participants