-
-
Notifications
You must be signed in to change notification settings - Fork 964
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
Conversation
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 | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
# Conflicts: # docs/docs/CHANGELOG.md
Related issue
Proposed changes
Checklist
contributing code guidelines.
vulnerability. If this pull request addresses a security. vulnerability, I
confirm that I got green light (please contact
security@ory.sh) from the maintainers to push
the changes.
works.
Further comments