-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for database events in Doctl (#1524)
* Add support for database events in Doctl * Add integration test list database events --------- Co-authored-by: Rahul Bhardwaj <[email protected]>
- Loading branch information
1 parent
ac0c4e9
commit 75b63a5
Showing
6 changed files
with
228 additions
and
0 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/http/httputil" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/sclevine/spec" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var _ = suite("database/events", func(t *testing.T, when spec.G, it spec.S) { | ||
var ( | ||
expect *require.Assertions | ||
server *httptest.Server | ||
) | ||
|
||
it.Before(func() { | ||
expect = require.New(t) | ||
|
||
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
switch req.URL.Path { | ||
case "/v2/databases/some-database-id/events": | ||
auth := req.Header.Get("Authorization") | ||
if auth != "Bearer some-magic-token" { | ||
w.WriteHeader(http.StatusTeapot) | ||
} | ||
|
||
if req.Method != http.MethodGet { | ||
w.WriteHeader(http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
w.Write([]byte(databaseListEventsResponse)) | ||
default: | ||
dump, err := httputil.DumpRequest(req, true) | ||
if err != nil { | ||
t.Fatal("failed to dump request") | ||
} | ||
|
||
t.Fatalf("received unknown request: %s", dump) | ||
} | ||
})) | ||
}) | ||
|
||
when("all required flags are passed", func() { | ||
it("lists users for the database", func() { | ||
cmd := exec.Command(builtBinaryPath, | ||
"-t", "some-magic-token", | ||
"-u", server.URL, | ||
"database", | ||
"events", | ||
"list", | ||
"some-database-id", | ||
) | ||
|
||
output, err := cmd.CombinedOutput() | ||
expect.NoError(err, fmt.Sprintf("received error output: %s", output)) | ||
expect.Equal(strings.TrimSpace(databaseListEventsOutput), strings.TrimSpace(string(output))) | ||
}) | ||
}) | ||
}) | ||
|
||
const ( | ||
databaseListEventsOutput = ` | ||
ID Cluster Name Type of Event Create Time | ||
pe8u2huh customer-events cluster_create 2020-10-29T15:57:38Z | ||
pe8ufefuh customer-events cluster_update 2023-10-30T15:57:38Z | ||
` | ||
databaseListEventsResponse = ` | ||
{ | ||
"events": [ | ||
{ | ||
"id": "pe8u2huh", | ||
"cluster_name": "customer-events", | ||
"event_type": "cluster_create", | ||
"create_time": "2020-10-29T15:57:38Z" | ||
}, | ||
{ | ||
"id": "pe8ufefuh", | ||
"cluster_name": "customer-events", | ||
"event_type": "cluster_update", | ||
"create_time": "2023-10-30T15:57:38Z" | ||
} | ||
] | ||
} | ||
` | ||
) |