Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(api): fix e2e cleanup operations #673

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions tests/e2e/affinity_toleration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,9 @@ var _ = Describe("Virtual machine affinity and toleration", ginkgoutil.CommonE2E
})
})

Context("When test is complited:", func() {
It("tries to delete used resources", func() {
kustimizationFile := fmt.Sprintf("%s/%s", conf.TestData.AffinityToleration, "kustomization.yaml")
err := kustomize.ExcludeResource(kustimizationFile, "ns.yaml")
Expect(err).NotTo(HaveOccurred(), "cannot exclude namespace from clean up operation:\n%s", err)
res := kubectl.Delete(kc.DeleteOptions{
Filename: []string{conf.TestData.AffinityToleration},
FilenameOption: kc.Kustomize,
})
Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr())
Context("When test is completed", func() {
It("deletes test case resources", func() {
DeleteTestCaseResources(ResourcesToDelete{KustomizationDir: conf.TestData.AffinityToleration})
})
})
})
59 changes: 32 additions & 27 deletions tests/e2e/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package e2e

import (
"encoding/json"
"errors"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -207,7 +208,7 @@ func GetObject(resource kc.Resource, name string, object client.Object, opts kc.
}
cmd := kubectl.GetResource(resource, name, cmdOpts)
if cmd.Error() != nil {
return fmt.Errorf(cmd.StdErr())
return errors.New(cmd.StdErr())
}
err := json.Unmarshal(cmd.StdOutBytes(), object)
if err != nil {
Expand Down Expand Up @@ -302,7 +303,7 @@ func GetDefaultStorageClass() (*storagev1.StorageClass, error) {
var scList storagev1.StorageClassList
res := kubectl.List(kc.ResourceStorageClass, kc.GetOptions{Output: "json"})
if !res.WasSuccess() {
return nil, fmt.Errorf(res.StdErr())
return nil, errors.New(res.StdErr())
}

err := json.Unmarshal([]byte(res.StdOut()), &scList)
Expand Down Expand Up @@ -459,31 +460,35 @@ type ResourcesToDelete struct {

// This function checks that all resources in test case can be deleted correctly.
func DeleteTestCaseResources(resources ResourcesToDelete) {
By("Response on deletion request should be successful")
const errMessage = "cannot delete test case resources"

if resources.KustomizationDir != "" {
res := kubectl.Delete(kc.DeleteOptions{
Filename: []string{resources.KustomizationDir},
FilenameOption: kc.Kustomize,
})
Expect(res.Error()).NotTo(HaveOccurred(), fmt.Sprintf("%s\nkustomizationDir: %s\ncmd: %s\nstderr: %s", errMessage, resources.KustomizationDir, res.GetCmd(), res.StdErr()))
}
By("Response on deletion request should be successful", func() {
const errMessage = "cannot delete test case resources"

if resources.KustomizationDir != "" {
kustimizationFile := fmt.Sprintf("%s/%s", resources.KustomizationDir, "kustomization.yaml")
err := kustomize.ExcludeResource(kustimizationFile, "ns.yaml")
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("%s\nkustomizationDir: %s\nstderr: %s", errMessage, resources.KustomizationDir, err))
res := kubectl.Delete(kc.DeleteOptions{
Filename: []string{resources.KustomizationDir},
FilenameOption: kc.Kustomize,
})
Expect(res.Error()).NotTo(HaveOccurred(), fmt.Sprintf("%s\nkustomizationDir: %s\ncmd: %s\nstderr: %s", errMessage, resources.KustomizationDir, res.GetCmd(), res.StdErr()))
}

for _, r := range resources.AdditionalResources {
res := kubectl.Delete(kc.DeleteOptions{
Labels: r.Labels,
Namespace: conf.Namespace,
Resource: r.Resource,
})
Expect(res.Error()).NotTo(HaveOccurred(), fmt.Sprintf("%s\ncmd: %s\nstderr: %s", errMessage, res.GetCmd(), res.StdErr()))
}
for _, r := range resources.AdditionalResources {
res := kubectl.Delete(kc.DeleteOptions{
Labels: r.Labels,
Namespace: conf.Namespace,
Resource: r.Resource,
})
Expect(res.Error()).NotTo(HaveOccurred(), fmt.Sprintf("%s\ncmd: %s\nstderr: %s", errMessage, res.GetCmd(), res.StdErr()))
}

if len(resources.Files) != 0 {
res := kubectl.Delete(kc.DeleteOptions{
Filename: resources.Files,
FilenameOption: kc.Filename,
})
Expect(res.Error()).NotTo(HaveOccurred(), fmt.Sprintf("%s\ncmd: %s\nstderr: %s", errMessage, res.GetCmd(), res.StdErr()))
}
if len(resources.Files) != 0 {
res := kubectl.Delete(kc.DeleteOptions{
Filename: resources.Files,
FilenameOption: kc.Filename,
})
Expect(res.Error()).NotTo(HaveOccurred(), fmt.Sprintf("%s\ncmd: %s\nstderr: %s", errMessage, res.GetCmd(), res.StdErr()))
}
})
}
3 changes: 1 addition & 2 deletions tests/e2e/vm_disk_resizing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/api/resource"

virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/tests/e2e/config"
cfg "github.com/deckhouse/virtualization/tests/e2e/config"
d8 "github.com/deckhouse/virtualization/tests/e2e/d8"
"github.com/deckhouse/virtualization/tests/e2e/ginkgoutil"
Expand Down Expand Up @@ -162,7 +161,7 @@ func GetVirtualMachineDisks(vmName string, config *cfg.Config) (VirtualMachineDi

var _ = Describe("Virtual disk resizing", ginkgoutil.CommonE2ETestDecorators(), func() {
BeforeEach(func() {
if config.IsReusable() {
if cfg.IsReusable() {
Skip("Test not available in REUSABLE mode: not supported yet.")
}
})
Expand Down
Loading