因此,我正在开发一个运行纠缠测试的PowerShell脚本.该脚本使用Mongo数据库连接到Kubernetes Pod.目标是判断数据库中的集合是否为空.我对代码一直到"返回计数"行都很满意.我知道在Shell中没有Return命令,但我把它放进go 是为了说明.
我实际上是在try 将"count"值从"kubectl exec"中提取到PowerShell代码中.这个是可能的吗?
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
}
}