Skip to content

Instantly share code, notes, and snippets.

@niski84
Created August 8, 2023 05:47
Show Gist options
  • Save niski84/61bc7cb868408f33080c5bca69f236ad to your computer and use it in GitHub Desktop.
Save niski84/61bc7cb868408f33080c5bca69f236ad to your computer and use it in GitHub Desktop.
clone rds test cases
package main
import "testing"
func TestCreateRDSSnapshot(t *testing.T) {
tests := []struct {
input CreateSnapshotInput
expect bool
}{
{CreateSnapshotInput{DBIdentifier: "mydbinstance"}, true},
{CreateSnapshotInput{DBIdentifier: "mydbinstance", SnapshotIdentifier: "custom-snapshot-identifier"}, true},
{CreateSnapshotInput{DBIdentifier: ""}, false}, // Invalid input; should return an error
}
for _, test := range tests {
err := CreateRDSSnapshot(test.input)
if (err != nil) != test.expect {
t.Errorf("CreateRDSSnapshot(%v) = %v, want %v", test.input, err, test.expect)
}
}
}
func TestFindRDSInstanceIdentifierByHostname(t *testing.T) {
dbHostName := "valid-hostname.example.com"
_, err := FindRDSInstanceIdentifierByHostname(dbHostName)
if err != nil {
t.Errorf("FindRDSInstanceIdentifierByHostname(%v) returned an error: %v", dbHostName, err)
}
}
func TestCreateRDSSnapshot(t *testing.T) {
dbIdentifier := "valid-db-identifier"
createSnapshotInput := CreateSnapshotInput{
DBIdentifier: dbIdentifier,
}
err := CreateRDSSnapshot(createSnapshotInput)
if err != nil {
t.Errorf("CreateRDSSnapshot(%v) returned an error: %v", createSnapshotInput, err)
}
}
func TestFindLatestSnapshotByHostname(t *testing.T) {
dbHostName := "valid-hostname.example.com"
_, err := FindLatestSnapshotByHostname(dbHostName)
if err != nil {
t.Errorf("FindLatestSnapshotByHostname(%v) returned an error: %v", dbHostName, err)
}
}
func TestRestoreRDSFromSnapshot(t *testing.T) {
latestSnapshotIdentifier := "latest-snapshot-identifier"
newRdsDBIdentifier := "new-db-identifier"
err := RestoreRDSFromSnapshot(latestSnapshotIdentifier, newRdsDBIdentifier)
if err != nil {
t.Errorf("RestoreRDSFromSnapshot(%v, %v) returned an error: %v", latestSnapshotIdentifier, newRdsDBIdentifier, err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment