2024-09-26 21:01:49 +02:00
|
|
|
package kubectl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestKubectStatefulset(t *testing.T) {
|
|
|
|
|
|
|
|
fileName := filepath.Join(TEST_SRC_DIR, "statefulset.json")
|
|
|
|
cmd_json, _ := os.ReadFile(fileName)
|
|
|
|
|
|
|
|
cmd := getCmdKubectl(true, string(cmd_json))
|
|
|
|
|
|
|
|
|
|
|
|
data := KubectlObject{Name: "dep1", Kind: "Statefulset"}
|
|
|
|
|
|
|
|
res, err := cmd.getStatefulSet(data)
|
|
|
|
|
|
|
|
assert.Nilf(t, err, "error message %s", err)
|
|
|
|
assert.Equal(t, "StatefulSet", res["kind"], "TestKubectStatefulset error")
|
|
|
|
assert.Equal(t, 1, res["replicas"], "TestKubectStatefulset error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestKubectStatefulsetPending(t *testing.T) {
|
|
|
|
|
|
|
|
fileName := filepath.Join(TEST_SRC_DIR, "mongo_pending.json")
|
|
|
|
cmd_json, _ := os.ReadFile(fileName)
|
|
|
|
|
|
|
|
cmd := getCmdKubectl(true, string(cmd_json))
|
|
|
|
|
|
|
|
data := KubectlObject{Name: "dep1", Kind: "Statefulset"}
|
|
|
|
|
|
|
|
res, err := cmd.getStatefulSet(data)
|
|
|
|
|
|
|
|
assert.Nilf(t, err, "error message %s", err)
|
|
|
|
assert.Equal(t, 1, res["unavailableReplicas"], "TestKubectStatefulsetPending error")
|
|
|
|
assert.Equal(t, "StatefulSet", res["kind"], "TestKubectStatefulsetPending error")
|
|
|
|
assert.Equal(t, 1, res["replicas"], "TestKubectStatefulsetPending error")
|
|
|
|
}
|