So I'm working on a powershell script that runs a pester test. The script connects to a Kubernetes pod with a Mongo database. The goal is to check whether or not a collection in the database is empty. I'm happy with the code up until the "return count" line. I'm aware there is no return command in shell, but I've put it in to illustrate.
I'm essentially trying to get the "count" value out from "kubectl exec" into the powershell code. Is this possible?
Context "Foo collection" {
It "should have no documents"{
kubectl exec -it $podName -n mongo `
-- mongosh -u root -p $mongoSecret `
--eval "`
db = db.getSiblingDB('thisOne')
collection = db.getCollection('foo')
count = collection.countDocuments({}, {limit: 1})
return count
"
$docs = count
$docs | Should -Be 0
}
}