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: New --private-key-file flag when creating a resource instance #670
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,15 @@ import ( | |
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/meroxa/cli/cmd/meroxa/builder" | ||
"github.com/meroxa/cli/cmd/meroxa/global" | ||
|
@@ -59,6 +64,9 @@ func TestCreateResourceFlags(t *testing.T) { | |
{name: "metadata", required: false, shorthand: "m"}, | ||
{name: "env", required: false}, | ||
{name: "token", required: false}, | ||
{name: "ssh-url", required: false}, | ||
{name: "ssh-private-key", required: false}, | ||
{name: "private-key-file", required: false}, | ||
} | ||
|
||
c := builder.BuildCobraCommand(&Create{}) | ||
|
@@ -358,3 +366,103 @@ Sign up for the Beta here: https://share.hsforms.com/1Uq6UYoL8Q6eV5QzSiyIQkAc2sm | |
t.Fatalf("expected output:\n%s\ngot:\n%s", wantError, gotError) | ||
} | ||
} | ||
|
||
func TestCreateResourceExecutionPrivateKeyFlags(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice test coverage as always! ✨ |
||
ctx := context.Background() | ||
logger := log.NewTestLogger() | ||
|
||
keyVal := "super-secret" | ||
keyFile := filepath.Join("/tmp", uuid.NewString()) | ||
err := os.WriteFile(keyFile, []byte(keyVal), 0600) | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
name string | ||
inputType string | ||
inputSSHPrivateKeyFlag string | ||
inputPasswordFlag string | ||
inputPrivateKeyFileFlag string | ||
expectedPassword string | ||
expectedSSHPrivateKeyVal string | ||
}{ | ||
{ | ||
name: "create postgres resource with SSH Tunnel --ssh-private-key", | ||
inputType: string(meroxa.ResourceTypePostgres), | ||
inputSSHPrivateKeyFlag: keyVal, | ||
expectedPassword: "", | ||
expectedSSHPrivateKeyVal: keyVal, | ||
}, | ||
{ | ||
name: "create postgres resource with SSH Tunnel --private-key-file", | ||
inputType: string(meroxa.ResourceTypePostgres), | ||
inputPrivateKeyFileFlag: keyFile, | ||
expectedPassword: "", | ||
expectedSSHPrivateKeyVal: keyVal, | ||
}, | ||
{ | ||
name: "create postgres resource with both SSH flags", | ||
inputType: string(meroxa.ResourceTypePostgres), | ||
inputPrivateKeyFileFlag: keyFile, | ||
inputSSHPrivateKeyFlag: keyVal, | ||
expectedPassword: "", | ||
expectedSSHPrivateKeyVal: keyVal, | ||
}, | ||
{ | ||
name: "create snowflake resource with --password", | ||
inputType: string(meroxa.ResourceTypeSnowflake), | ||
inputPasswordFlag: keyVal, | ||
expectedPassword: keyVal, | ||
expectedSSHPrivateKeyVal: "", | ||
}, | ||
{ | ||
name: "create snowflake resource with --private-key-file", | ||
inputPrivateKeyFileFlag: keyFile, | ||
inputType: string(meroxa.ResourceTypeSnowflake), | ||
expectedPassword: keyVal, | ||
expectedSSHPrivateKeyVal: keyVal, | ||
}, | ||
{ | ||
name: "create snowflake resource with both secret flags", | ||
inputPasswordFlag: keyVal, | ||
inputPrivateKeyFileFlag: keyFile, | ||
inputType: string(meroxa.ResourceTypeSnowflake), | ||
expectedPassword: keyVal, | ||
expectedSSHPrivateKeyVal: keyVal, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
client := mock.NewMockClient(ctrl) | ||
|
||
c := &Create{ | ||
client: client, | ||
logger: logger, | ||
} | ||
|
||
client. | ||
EXPECT(). | ||
CreateResource( | ||
ctx, | ||
gomock.Any(), | ||
). | ||
Return(&meroxa.Resource{}, nil) | ||
|
||
c.args.Name = "my-resource" | ||
c.flags.Type = tc.inputType | ||
c.flags.URL = "anything" | ||
c.flags.Password = tc.inputPasswordFlag | ||
c.flags.SSHPrivateKey = tc.inputSSHPrivateKeyFlag | ||
c.flags.PrivateKeyFile = tc.inputPrivateKeyFileFlag | ||
|
||
err := c.Execute(ctx) | ||
if err != nil { | ||
t.Fatalf("not expected error, got %q", err.Error()) | ||
} | ||
|
||
assert.Equalf(t, tc.expectedSSHPrivateKeyVal, c.flags.SSHPrivateKey, "mistach in private key flag value") | ||
assert.Equalf(t, tc.expectedPassword, c.flags.Password, "mismatch in password flag value") | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
That's neat and as you already said, super helpful with creating snowflake resources in particular!