-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from neo4j/use-test-helper
Aura API commands to use new test helper
- Loading branch information
Showing
12 changed files
with
336 additions
and
1,185 deletions.
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
76 changes: 11 additions & 65 deletions
76
neo4j/aura/internal/subcommands/customermanagedkey/delete_test.go
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 |
---|---|---|
@@ -1,81 +1,27 @@ | ||
package customermanagedkey_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/neo4j/cli/common/clicfg" | ||
"github.com/neo4j/cli/common/clictx" | ||
"github.com/neo4j/cli/neo4j/aura" | ||
"github.com/neo4j/cli/test/utils/testfs" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/neo4j/cli/neo4j/aura/internal/test/testutils" | ||
) | ||
|
||
func TestDeleteCustomerManagedKey(t *testing.T) { | ||
assert := assert.New(t) | ||
for _, command := range []string{"customer-managed-key", "cmk"} { | ||
helper := testutils.NewAuraTestHelper(t) | ||
defer helper.Close() | ||
|
||
cmkId := "8c764aed-8eb3-4a1c-92f6-e4ef0c7a6ed9" | ||
cmkId := "8c764aed-8eb3-4a1c-92f6-e4ef0c7a6ed9" | ||
|
||
mux := http.NewServeMux() | ||
mockHandler := helper.NewRequestHandlerMock(fmt.Sprintf("/v1/customer-managed-keys/%s", cmkId), http.StatusNoContent, "") | ||
|
||
var authCounter = 0 | ||
mux.HandleFunc("/oauth/token", func(res http.ResponseWriter, req *http.Request) { | ||
authCounter++ | ||
helper.ExecuteCommand(fmt.Sprintf("%s delete %s", command, cmkId)) | ||
|
||
res.WriteHeader(200) | ||
res.Write([]byte(`{"access_token":"12345678","expires_in":3600,"token_type":"bearer"}`)) | ||
}) | ||
mockHandler.AssertCalledTimes(1) | ||
mockHandler.AssertCalledWithMethod(http.MethodDelete) | ||
|
||
var getCounter = 0 | ||
mux.HandleFunc(fmt.Sprintf("/v1/customer-managed-keys/%s", cmkId), func(res http.ResponseWriter, req *http.Request) { | ||
getCounter++ | ||
|
||
assert.Equal(http.MethodDelete, req.Method) | ||
assert.Equal(fmt.Sprintf("/v1/customer-managed-keys/%s", cmkId), req.URL.Path) | ||
|
||
res.WriteHeader(204) | ||
}) | ||
|
||
server := httptest.NewServer(mux) | ||
defer server.Close() | ||
|
||
cmd := aura.NewCmd() | ||
b := bytes.NewBufferString("") | ||
cmd.SetOut(b) | ||
cmd.SetArgs([]string{"customer-managed-key", "delete", "--auth-url", fmt.Sprintf("%s/oauth/token", server.URL), "--base-url", fmt.Sprintf("%s/v1", server.URL), cmkId}) | ||
|
||
fs, err := testfs.GetTestFs(`{ | ||
"aura": { | ||
"credentials": [{ | ||
"name": "test-cred", | ||
"access-token": "dsa", | ||
"token-expiry": 123 | ||
}], | ||
"default-credential": "test-cred" | ||
} | ||
}`) | ||
assert.Nil(err) | ||
|
||
cfg, err := clicfg.NewConfig(fs) | ||
assert.Nil(err) | ||
|
||
ctx, err := clictx.NewContext(context.Background(), cfg, "test") | ||
assert.Nil(err) | ||
|
||
err = cmd.ExecuteContext(ctx) | ||
assert.Nil(err) | ||
|
||
out, err := io.ReadAll(b) | ||
assert.Nil(err) | ||
|
||
assert.Equal(1, authCounter) | ||
assert.Equal(1, getCounter) | ||
|
||
assert.Equal(`Operation Successful | ||
`, string(out)) | ||
helper.AssertOut("Operation Successful\n") | ||
} | ||
} |
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
Oops, something went wrong.