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

feat: add helper for starting kratos e2e #1469

Merged
merged 6 commits into from
Jun 30, 2021
Merged

feat: add helper for starting kratos e2e #1469

merged 6 commits into from
Jun 30, 2021

Conversation

aeneasr
Copy link
Member

@aeneasr aeneasr commented Jun 29, 2021

Related issue

Proposed changes

Checklist

Further comments

Comment on lines +25 to +63
func setup(t *testing.T, cmd *cobra.Command) driver.Registry {
conf, reg := internal.NewFastRegistryWithMocks(t)
_, admin := testhelpers.NewKratosServerWithCSRF(t, reg)
conf.MustSet(config.ViperKeyDefaultIdentitySchemaURL, "file://./stubs/identity.schema.json")
// setup command
cliclient.RegisterClientFlags(cmd.Flags())
cmdx.RegisterFormatFlags(cmd.Flags())
require.NoError(t, cmd.Flags().Set(cliclient.FlagEndpoint, admin.URL))
require.NoError(t, cmd.Flags().Set(cmdx.FlagFormat, string(cmdx.FormatJSON)))
return reg
}

func exec(cmd *cobra.Command, stdIn io.Reader, args ...string) (string, string, error) {
stdOut, stdErr := &bytes.Buffer{}, &bytes.Buffer{}
cmd.SetErr(stdErr)
cmd.SetOut(stdOut)
cmd.SetIn(stdIn)
defer cmd.SetIn(nil)
if args == nil {
args = []string{}
}
cmd.SetArgs(args)
err := cmd.Execute()
return stdOut.String(), stdErr.String(), err
}

func execNoErr(t *testing.T, cmd *cobra.Command, args ...string) string {
stdOut, stdErr, err := exec(cmd, nil, args...)
require.NoError(t, err)
require.Len(t, stdErr, 0, stdOut)
return stdOut
}

func execErr(t *testing.T, cmd *cobra.Command, args ...string) string {
stdOut, stdErr, err := exec(cmd, nil, args...)
require.True(t, errors.Is(err, cmdx.ErrNoPrintButFail))
require.Len(t, stdOut, 0, stdErr)
return stdErr
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is now part of cmdx, maybe remove it in this go? I can also do that btw

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah makes sense, I first have to wrap everything in new* funcs to make it pass. We can then do another pass and remove these helpers and move to ory/x. Would be great if you could do that. I think it makes sense to do it once this PR is merged

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are already in ory/x 1:1, you can just remove them here and import instead. But we can also separate that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method signatures are a bit different so I'd separate it

@aeneasr aeneasr merged commit b9c7674 into master Jun 30, 2021
@aeneasr aeneasr deleted the serve-cmd branch June 30, 2021 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants