Skip to content

Commit

Permalink
integration: cleanup to AfterAll and BeforeSuite
Browse files Browse the repository at this point in the history
The outer Describe block needs to be Ordered to be able to use
AfterAll inside it. Cleanup in BeforeSuite and AfterAll functions
should take care of clean environment before and after each testcase.
  • Loading branch information
jsliacan authored and cfergeau committed Sep 5, 2023
1 parent ddb2e4c commit 8d849aa
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 8 deletions.
30 changes: 29 additions & 1 deletion test/integration/podman_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
package test_test

import (
"fmt"
"os"
"os/user"
"path/filepath"
"runtime"

"github.com/crc-org/crc/test/extended/crc/cmd"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
)

var _ = Describe("podman preset", Serial, Label("podman-preset"), func() {
var _ = Describe("podman preset", Serial, Ordered, Label("podman-preset"), func() {

// runs 1x after all the It blocks (specs) inside this Describe node
AfterAll(func() {
fmt.Println("AfterAll 1")
// set userHome
usr, err := user.Current()
Expect(err).NotTo(HaveOccurred())

userHome = usr.HomeDir

// cleanup CRC
Expect(RunCRCExpectSuccess("cleanup")).To(MatchRegexp("Cleanup finished"))

// remove config file
configFilePath := filepath.Join(userHome, ".crc", "crc.json")
err = os.RemoveAll(configFilePath)
if err != nil {
logrus.Infof("could not delete %s.", configFilePath)
logrus.Infof("%v", err)
}
Expect(err).NotTo(HaveOccurred())

})

fmt.Println("suite 1")
Describe("basic use", Serial, Ordered, func() {
fmt.Println("suite 1.1")
It("write to config", func() {
Expect(RunCRCExpectSuccess("config", "set", "preset", "podman")).To(ContainSubstring("Changes to configuration property 'preset' are only applied when the CRC instance is created."))
})
Expand Down
32 changes: 30 additions & 2 deletions test/integration/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,47 @@ package test_test

import (
"fmt"
"os"
"os/exec"
"os/user"
"path/filepath"

"github.com/crc-org/crc/test/extended/util"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
)

var _ = Describe("", Serial, Label("openshift-preset", "goproxy"), func() {
var _ = Describe("", Serial, Ordered, Label("openshift-preset", "goproxy"), func() {

// runs 1x after all the It blocks (specs) inside this Describe node
AfterAll(func() {

fmt.Println("AfterAll 2")
// set userHome
usr, err := user.Current()
Expect(err).NotTo(HaveOccurred())
userHome = usr.HomeDir

// cleanup CRC
Expect(RunCRCExpectSuccess("cleanup")).To(MatchRegexp("Cleanup finished"))

// remove config file
configFilePath := filepath.Join(userHome, ".crc", "crc.json")
err = os.RemoveAll(configFilePath)
if err != nil {
logrus.Infof("could not delete %s.", configFilePath)
logrus.Infof("%v", err)
}
Expect(err).NotTo(HaveOccurred())

})

fmt.Println("suite 2")
go util.RunProxy()

Describe("Behind proxy", Serial, Ordered, func() {

fmt.Println("suite 2.1")
networkMode := "user"
httpProxy := "http://127.0.0.1:8888"
httpsProxy := "http://127.0.0.1:8888"
Expand Down
39 changes: 34 additions & 5 deletions test/integration/resize_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
package test_test

import (
"fmt"
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
)

var _ = Describe("vary VM parameters: memory cpus, disk", Serial, Label("openshift-preset", "vm-resize"), func() {
var _ = Describe("vary VM parameters: memory cpus, disk", Serial, Ordered, Label("openshift-preset", "vm-resize"), func() {

// runs 1x after all the It blocks (specs) inside this Describe node
AfterAll(func() {
fmt.Println("AfterAll 3")
// set userHome
usr, err := user.Current()
Expect(err).NotTo(HaveOccurred())
userHome = usr.HomeDir

// cleanup CRC
Expect(RunCRCExpectSuccess("cleanup")).To(MatchRegexp("Cleanup finished"))

// remove config file
configFilePath := filepath.Join(userHome, ".crc", "crc.json")
err = os.RemoveAll(configFilePath)
if err != nil {
logrus.Infof("could not delete %s.", configFilePath)
logrus.Infof("%v", err)
}
Expect(err).NotTo(HaveOccurred())

Describe("use default values", Serial, Ordered, func() {
})

fmt.Println("suite 3")

Describe("use default values", Serial, Ordered, func() {
fmt.Println("suite 3.1")
It("setup CRC", func() {
if bundlePath == "" {
Expect(RunCRCExpectSuccess("setup")).To(ContainSubstring("Your system is correctly setup for using CRC"))
Expand Down Expand Up @@ -74,7 +103,7 @@ var _ = Describe("vary VM parameters: memory cpus, disk", Serial, Label("openshi
})

Describe("use custom values", Serial, Ordered, func() {

fmt.Println("suite 3.2")
It("start CRC", func() {
Expect(RunCRCExpectSuccess("start", "--memory", "13000", "--cpus", "6", "--disk-size", "50")).To(ContainSubstring("Started the OpenShift cluster"))
})
Expand Down Expand Up @@ -104,7 +133,7 @@ var _ = Describe("vary VM parameters: memory cpus, disk", Serial, Label("openshi
})

Describe("use flawed values", Serial, Ordered, func() {

fmt.Println("suite 3.3")
It("start CRC with sub-minimum memory", func() { // less than min = 9216
Expect(RunCRCExpectFail("start", "--memory", "9000")).To(ContainSubstring("requires memory in MiB >= 9216"))
})
Expand All @@ -124,7 +153,7 @@ var _ = Describe("vary VM parameters: memory cpus, disk", Serial, Label("openshi
})

Describe("use default values again", Serial, Ordered, func() {

fmt.Println("suite 3.4")
It("start CRC", func() {
Expect(RunCRCExpectSuccess("start")).To(ContainSubstring("Started the OpenShift cluster")) // default values: "--memory", "9216", "--cpus", "4", "disk-size", "31"
})
Expand Down
2 changes: 2 additions & 0 deletions test/integration/testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test_test

import (
"encoding/json"
"fmt"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -55,6 +56,7 @@ var _ = BeforeSuite(func() {

userHome = usr.HomeDir

fmt.Println("BeforeSuite")
// cleanup CRC
Expect(RunCRCExpectSuccess("cleanup")).To(MatchRegexp("Cleanup finished"))

Expand Down

0 comments on commit 8d849aa

Please sign in to comment.