diff --git a/integration-tests/integrationTestUtils/integrationTestUtils.go b/integration-tests/integrationTestUtils/integrationTestUtils.go index daf272f74c1cd1d30c9dd68bc76f2bf8a8f5cbef..271be882d7ec1a226bf05c206238262fb3407eec 100644 --- a/integration-tests/integrationTestUtils/integrationTestUtils.go +++ b/integration-tests/integrationTestUtils/integrationTestUtils.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "os/exec" "time" configMgmtPb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/configurationmanagement" @@ -192,3 +193,57 @@ func cleanRolesExceptAdmin(resp *apb.GetRolesResponse, roleService apb.RoleServi return nil } + +func ClearRabbitMQQueues() { + rabbitMQAddress := "localhost" + envVarRabbitmq := os.Getenv("RABBITMQ") + if envVarRabbitmq != "" { + rabbitMQAddress = envVarRabbitmq + } + + // add more queue names if necessary + queues := []string{ + "user", + "role", + "managedNetworkElement", + } + + // for _, queue := range queues { + // args := []string{ + // "-X", "DELETE", + // "-u", "guest:guest", + // "http://" + rabbitMQAddress + ":15672/api/queues/%2f/" + queue, + // "--write-out", "%{http_code}", + // } + + // cmd := exec.Command("curl", args...) + // cmd.Stdout = os.Stdout + // cmd.Stderr = os.Stderr + // err := cmd.Run() + // if err != nil { + // logrus.Info(err) + // } + // } + + // -i -u guest:guest -H "content-type:application/json" -X POST http://127.0.0.1:15672/api/queues/foo/get -d '{"count":5,"requeue":true,"encoding":"auto","truncate":50000}' + + for _, queue := range queues { + args := []string{ + "-i", + "-u", "guest:guest", + "-H", "\"content-type:application/json\"", + "-X", "POST", + "http://" + rabbitMQAddress + ":15672/api/queues/%2f/" + queue + "/get", + "-d", "{\"count\":10,\"encoding\":\"auto\",\"truncate\":50000,\"ackmode\":\"ack_requeue_true\"}", + } + + cmd := exec.Command("curl", args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + err := cmd.Run() + if err != nil { + logrus.Info(err) + } + } +}