2022-09-05 04:01:14 +00:00
|
|
|
package kubernetes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPersistentVolumeClaim(t *testing.T) {
|
|
|
|
expectedRwx := `
|
|
|
|
{
|
|
|
|
"metadata": {
|
2023-03-21 19:00:45 +00:00
|
|
|
"name": "somename",
|
2022-09-05 04:01:14 +00:00
|
|
|
"namespace": "someNamespace",
|
|
|
|
"creationTimestamp": null
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"accessModes": [
|
|
|
|
"ReadWriteMany"
|
|
|
|
],
|
|
|
|
"resources": {
|
|
|
|
"requests": {
|
|
|
|
"storage": "1Gi"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"storageClassName": "local-storage"
|
|
|
|
},
|
|
|
|
"status": {}
|
|
|
|
}`
|
|
|
|
|
|
|
|
expectedRwo := `
|
|
|
|
{
|
|
|
|
"metadata": {
|
2023-03-21 19:00:45 +00:00
|
|
|
"name": "somename",
|
2022-09-05 04:01:14 +00:00
|
|
|
"namespace": "someNamespace",
|
|
|
|
"creationTimestamp": null
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"accessModes": [
|
|
|
|
"ReadWriteOnce"
|
|
|
|
],
|
|
|
|
"resources": {
|
|
|
|
"requests": {
|
|
|
|
"storage": "1Gi"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"storageClassName": "local-storage"
|
|
|
|
},
|
|
|
|
"status": {}
|
|
|
|
}`
|
|
|
|
|
2023-03-21 19:00:45 +00:00
|
|
|
pvc, err := PersistentVolumeClaim("someNamespace", "somename", "local-storage", "1Gi", true)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2022-09-05 04:01:14 +00:00
|
|
|
j, err := json.Marshal(pvc)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.JSONEq(t, expectedRwx, string(j))
|
|
|
|
|
2023-03-21 19:00:45 +00:00
|
|
|
pvc, err = PersistentVolumeClaim("someNamespace", "somename", "local-storage", "1Gi", false)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2022-09-05 04:01:14 +00:00
|
|
|
j, err = json.Marshal(pvc)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.JSONEq(t, expectedRwo, string(j))
|
2023-03-21 19:00:45 +00:00
|
|
|
|
|
|
|
_, err = PersistentVolumeClaim("someNamespace", "some0INVALID3name", "local-storage", "1Gi", false)
|
|
|
|
assert.NotNil(t, err)
|
2022-09-05 04:01:14 +00:00
|
|
|
}
|