Skip to content

Instantly share code, notes, and snippets.

@guillaumerose
Last active August 5, 2020 20:30
Show Gist options
  • Save guillaumerose/421fcbecb2504a0d0bfad8156a5dd4f4 to your computer and use it in GitHub Desktop.
Save guillaumerose/421fcbecb2504a0d0bfad8156a5dd4f4 to your computer and use it in GitHub Desktop.
ginkgo demo
package test_test
import (
"bytes"
"encoding/json"
"fmt"
"io"
"math/rand"
"os/exec"
"strings"
"syscall"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
)
var _ = BeforeSuite(func() {
// something
})
var _ = Describe("basic commands", func() {
Describe("version", func() {
It("show version", func() {
Expect(RunCRCOrDie("version")).To(ContainSubstring("CodeReady Containers version"))
})
It("show version as json format", func() {
Skip("broken")
raw := RunCRCOrDie("version", "-o", "json")
var parsed map[string]string
Expect(json.Unmarshal([]byte(raw), &parsed)).To(Not(HaveOccurred()))
Expect(parsed).To(Equal(map[string]string{
"version": "1.0",
}))
})
})
Describe("health story", func() {
It("should setup crc", func() {
Skip("too long for demo")
RunCRCOrDie("setup")
})
It("should start crc virtual machine", func() {
Skip("too long for demo")
NewCRCCommand("start").WithTimeout(time.After(10 * time.Minute)).ExecOrDie()
})
It("should be ready", func() {
By("using crc command")
Eventually(func() (string, error) {
return RunCRC("status")
}, 2*time.Minute, 5*time.Second).Should(MatchRegexp(`.*Running \(v\d+\.\d+\.\d+.*\).*`))
By("looking at node status")
Eventually(func() (string, error) {
return RunOC("get", "nodes")
}, 2*time.Minute, 5*time.Second).Should(And(ContainSubstring("Ready"), Not(ContainSubstring("Not ready"))))
})
It("should be able to create a new project and an app", func() {
projectName := fmt.Sprintf("testproj%d", rand.Int())
defer func() {
RunOCOrDie("delete", "project", projectName)
}()
Expect(RunOCOrDie("new-project", projectName)).To(Or(
ContainSubstring(fmt.Sprintf(`Now using project "%s" on server "https://api.crc.testing:6443".`, projectName)),
ContainSubstring(fmt.Sprintf(`Already on project "%s" on server "https://api.crc.testing:6443".`, projectName))))
Expect(RunOCOrDie("new-app", "httpd-example")).To(ContainSubstring(`service "httpd-example" created`))
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment