mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-22 22:39:40 +00:00
Cypress: new 'Multiple Namespaces' test (#600)
This commit is contained in:
parent
9771d689ca
commit
a2eff2654d
@ -4,5 +4,10 @@
|
|||||||
"viewportHeight": 1080,
|
"viewportHeight": 1080,
|
||||||
"video": false,
|
"video": false,
|
||||||
"screenshotOnRunFailure": false,
|
"screenshotOnRunFailure": false,
|
||||||
"testFiles": ["tests/GuiPort.js"]
|
"testFiles":
|
||||||
|
["tests/GuiPort.js",
|
||||||
|
"tests/MultipleNamespaces.js"],
|
||||||
|
"env": {
|
||||||
|
"testUrl": "http://localhost:8899/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
const columns = {"podName" : 1, "namespace" : 2, "tapping" : 3}
|
||||||
|
const greenStatusImageSrc = "/static/media/success.662997eb.svg"
|
||||||
|
|
||||||
|
it('opening', function () {
|
||||||
|
cy.visit(Cypress.env('testUrl'))
|
||||||
|
cy.get('.podsCount').trigger('mouseover')
|
||||||
|
});
|
||||||
|
|
||||||
|
[1, 2, 3].map(doItFunc)
|
||||||
|
|
||||||
|
function doItFunc(number) {
|
||||||
|
const podName = Cypress.env(`name${number}`)
|
||||||
|
const namespace = Cypress.env(`namespace${number}`)
|
||||||
|
|
||||||
|
it(`verifying the pod (${podName}, ${namespace})`, function () {
|
||||||
|
findLineAndCheck({"podName" : podName, "namespace" : namespace})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDomPathInStatusBar(line, column) {
|
||||||
|
return `.expandedStatusBar > :nth-child(2) > > :nth-child(2) > :nth-child(${line}) > :nth-child(${column})`
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkLine(line, expectedValues) {
|
||||||
|
cy.get(getDomPathInStatusBar(line, columns.podName)).invoke('text').then(podValue => {
|
||||||
|
const podName = podValue.substring(0, podValue.indexOf('-'))
|
||||||
|
expect(podName).to.equal(expectedValues.podName)
|
||||||
|
|
||||||
|
cy.get(getDomPathInStatusBar(line, columns.namespace)).invoke('text').then(namespaceValue => {
|
||||||
|
expect(namespaceValue).to.equal(expectedValues.namespace)
|
||||||
|
cy.get(getDomPathInStatusBar(line, columns.tapping)).children().should('have.attr', 'src', greenStatusImageSrc)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function findLineAndCheck(expectedValues) {
|
||||||
|
cy.get('.expandedStatusBar > :nth-child(2) > > :nth-child(2) > > :nth-child(1)').then(pods => {
|
||||||
|
cy.get('.expandedStatusBar > :nth-child(2) > > :nth-child(2) > > :nth-child(2)').then(namespaces => {
|
||||||
|
|
||||||
|
// organizing namespaces array
|
||||||
|
const namespacesObjectsArray = Object.values(namespaces)
|
||||||
|
let namespacesArray = []
|
||||||
|
namespacesObjectsArray.forEach(line => {
|
||||||
|
line.getAttribute ? namespacesArray.push(line.innerHTML) : null
|
||||||
|
})
|
||||||
|
|
||||||
|
// organizing pods array
|
||||||
|
const podObjectsArray = Object.values(pods)
|
||||||
|
let podsArray = []
|
||||||
|
podObjectsArray.forEach(line => {
|
||||||
|
line.getAttribute ? podsArray.push(line.innerHTML.substring(0, line.innerHTML.indexOf('-'))) : null
|
||||||
|
})
|
||||||
|
|
||||||
|
let rightIndex = -1
|
||||||
|
podsArray.forEach((element, index) => {
|
||||||
|
if (element === expectedValues.podName && namespacesArray[index] === expectedValues.namespace) {
|
||||||
|
rightIndex = index + 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
rightIndex === -1 ? throwError(expectedValues.podName, expectedValues.namespace) : checkLine(rightIndex, expectedValues)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function throwError(pod, namespace) {
|
||||||
|
throw new Error(`The pod named ${pod} doesn't match any namespace named ${namespace}`)
|
||||||
|
}
|
@ -151,6 +151,7 @@ func TestTapAllNamespaces(t *testing.T) {
|
|||||||
|
|
||||||
expectedPods := []PodDescriptor{
|
expectedPods := []PodDescriptor{
|
||||||
{Name: "httpbin", Namespace: "mizu-tests"},
|
{Name: "httpbin", Namespace: "mizu-tests"},
|
||||||
|
{Name: "httpbin2", Namespace: "mizu-tests"},
|
||||||
{Name: "httpbin", Namespace: "mizu-tests2"},
|
{Name: "httpbin", Namespace: "mizu-tests2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,25 +185,8 @@ func TestTapAllNamespaces(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
podsUrl := fmt.Sprintf("%v/status/tap", apiServerUrl)
|
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/MultipleNamespaces.js\" --env name1=%v,name2=%v,name3=%v,namespace1=%v,namespace2=%v,namespace3=%v",
|
||||||
requestResult, requestErr := executeHttpGetRequest(podsUrl)
|
expectedPods[0].Name, expectedPods[1].Name, expectedPods[2].Name, expectedPods[0].Namespace, expectedPods[1].Namespace, expectedPods[2].Namespace))
|
||||||
if requestErr != nil {
|
|
||||||
t.Errorf("failed to get tap status, err: %v", requestErr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pods, err := getPods(requestResult)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("failed to get pods, err: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, expectedPod := range expectedPods {
|
|
||||||
if !isPodDescriptorInPodArray(pods, expectedPod) {
|
|
||||||
t.Errorf("unexpected result - expected pod not found, pod namespace: %v, pod name: %v", expectedPod.Namespace, expectedPod.Name)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTapMultipleNamespaces(t *testing.T) {
|
func TestTapMultipleNamespaces(t *testing.T) {
|
||||||
@ -250,30 +234,8 @@ func TestTapMultipleNamespaces(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
podsUrl := fmt.Sprintf("%v/status/tap", apiServerUrl)
|
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/MultipleNamespaces.js\" --env name1=%v,name2=%v,name3=%v,namespace1=%v,namespace2=%v,namespace3=%v",
|
||||||
requestResult, requestErr := executeHttpGetRequest(podsUrl)
|
expectedPods[0].Name, expectedPods[1].Name, expectedPods[2].Name, expectedPods[0].Namespace, expectedPods[1].Namespace, expectedPods[2].Namespace))
|
||||||
if requestErr != nil {
|
|
||||||
t.Errorf("failed to get tap status, err: %v", requestErr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pods, err := getPods(requestResult)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("failed to get pods, err: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(expectedPods) != len(pods) {
|
|
||||||
t.Errorf("unexpected result - expected pods length: %v, actual pods length: %v", len(expectedPods), len(pods))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, expectedPod := range expectedPods {
|
|
||||||
if !isPodDescriptorInPodArray(pods, expectedPod) {
|
|
||||||
t.Errorf("unexpected result - expected pod not found, pod namespace: %v, pod name: %v", expectedPod.Namespace, expectedPod.Name)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTapRegex(t *testing.T) {
|
func TestTapRegex(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user