Skip to content

Commit 4c36ccf

Browse files
authored
CLOUDP-307074: Add streams deletion to cleanup task (#3754)
1 parent 48775e5 commit 4c36ccf

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

test/e2e/atlas/cleanup_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ func TestCleanup(t *testing.T) {
9797
deleteAllPrivateEndpoints(t, cliPath, projectID, p)
9898
})
9999
}
100+
t.Run("delete all streams", func(t *testing.T) {
101+
t.Parallel()
102+
deleteAllStreams(t, cliPath, projectID)
103+
})
104+
100105
t.Run("delete all clusters", func(t *testing.T) {
101106
t.Parallel()
102107
deleteAllClustersForProject(t, cliPath, projectID)

test/e2e/atlas/helper_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,71 @@ func deleteAllPrivateEndpoints(t *testing.T, cliPath, projectID, provider string
720720
require.True(t, done, "failed to clean all private endpoints")
721721
}
722722

723+
func deleteAllStreams(t *testing.T, cliPath, projectID string) {
724+
t.Helper()
725+
726+
streams := listStreamsByProject(t, cliPath, projectID)
727+
if streams.GetTotalCount() == 0 {
728+
return
729+
}
730+
731+
for _, stream := range streams.GetResults() {
732+
deleteStream(t, cliPath, projectID, *stream.Name)
733+
}
734+
735+
done := false
736+
for attempt := 0; attempt < 10; attempt++ {
737+
streams = listStreamsByProject(t, cliPath, projectID)
738+
if streams.GetTotalCount() == 0 {
739+
t.Logf("all streams successfully deleted")
740+
done = true
741+
break
742+
}
743+
time.Sleep(sleep)
744+
}
745+
746+
require.True(t, done, "failed to clean all streams")
747+
}
748+
749+
func listStreamsByProject(t *testing.T, cliPath, projectID string) *atlasv2.PaginatedApiStreamsTenant {
750+
t.Helper()
751+
cmd := exec.Command(cliPath,
752+
streamsEntity,
753+
"instance",
754+
"list",
755+
"--projectId",
756+
projectID,
757+
"-o=json",
758+
)
759+
760+
cmd.Env = os.Environ()
761+
resp, err := e2e.RunAndGetStdOut(cmd)
762+
t.Log(string(resp))
763+
require.NoError(t, err, string(resp))
764+
var streams *atlasv2.PaginatedApiStreamsTenant
765+
require.NoError(t, json.Unmarshal(resp, &streams))
766+
767+
return streams
768+
}
769+
770+
func deleteStream(t *testing.T, cliPath, projectID, streamID string) {
771+
t.Helper()
772+
773+
cmd := exec.Command(cliPath,
774+
streamsEntity,
775+
"instance",
776+
"delete",
777+
"--force",
778+
streamID,
779+
"--projectId",
780+
projectID,
781+
"--force",
782+
)
783+
cmd.Env = os.Environ()
784+
resp, err := e2e.RunAndGetStdOut(cmd)
785+
require.NoError(t, err, string(resp))
786+
}
787+
723788
func listPrivateEndpointsByProject(t *testing.T, cliPath, projectID, provider string) []atlasv2.EndpointService {
724789
t.Helper()
725790
cmd := exec.Command(cliPath,

0 commit comments

Comments
 (0)