File: testsuite_test.go

package info (click to toggle)
golang-github-crc-org-crc 2.34.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,548 kB
  • sloc: sh: 398; makefile: 326; javascript: 40
file content (96 lines) | stat: -rw-r--r-- 2,307 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package test_test

import (
	"encoding/json"
	"os"
	"os/user"
	"path/filepath"
	"testing"

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

type VersionAnswer struct {
	Version          string `json:"version"`
	Commit           string `json:"commit"`
	OpenshiftVersion string `json:"openshiftVersion"`
}

var credPath string
var userHome string
var versionInfo VersionAnswer

var bundlePath string
var ginkgoOpts string
var pullSecretPath string

func TestTest(t *testing.T) {

	RegisterFailHandler(Fail)

	// disable error/output strings truncation
	gomegaformat.MaxLength = 0

	// fetch the current (reporter) config
	suiteConfig, reporterConfig := GinkgoConfiguration()

	err := os.MkdirAll("out", 0775)
	if err != nil {
		logrus.Infof("failed to create directory: %v", err)
	}
	reporterConfig.JUnitReport = filepath.Join("out", "integration.xml")

	RunSpecs(t, "Integration", suiteConfig, reporterConfig)

}

var _ = BeforeSuite(func() {

	// set userHome
	usr, err := user.Current()
	Expect(err).NotTo(HaveOccurred())
	userHome = usr.HomeDir
	util.CRCHome = filepath.Join(userHome, ".crc")

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

	// remove config file crc.json
	err = util.RemoveCRCConfig()
	Expect(err).NotTo(HaveOccurred())

	// set credPath
	credPath = filepath.Join(userHome, ".crc", "machines", "crc", "id_rsa")

	// find out if bundle embedded in the binary
	raw := RunCRCExpectSuccess("version", "-o", "json")
	err = json.Unmarshal([]byte(raw), &versionInfo)

	Expect(err).NotTo(HaveOccurred())

	bundlePath = os.Getenv("BUNDLE_PATH") // this env var should contain location of bundle
	if bundlePath != "" {
		Expect(bundlePath).To(BeAnExistingFile())
	}

	ginkgoOpts = os.Getenv("GINKGO_OPTS")
	if err != nil {

		logrus.Infof("Error: Could not read GINKGO_OPTS.")
		logrus.Infof("%v", err)
	}
	Expect(err).NotTo(HaveOccurred())

	pullSecretPath = os.Getenv("PULL_SECRET_PATH") // this env var should contain location of pull-secret file
	if err != nil {

		logrus.Infof("Error: You need to set PULL_SECRET_PATH to find CRC useful.")
		logrus.Infof("%v", err)
	}
	Expect(err).NotTo(HaveOccurred())

})