forked from oVirt/go-ovirt-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
67 lines (58 loc) · 1.68 KB
/
main_test.go
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
package ovirtclient_test
import (
"flag"
"fmt"
"os"
"testing"
ovirtclientlog "github.com/ovirt/go-ovirt-client-log/v3"
ovirtclient "github.com/ovirt/go-ovirt-client/v3"
)
var getHelper func(t *testing.T) ovirtclient.TestHelper
func getHelperLive(t *testing.T) ovirtclient.TestHelper {
helper, err := ovirtclient.NewLiveTestHelperFromEnv(ovirtclientlog.NewTestLogger(t))
if err != nil {
t.Fatal(fmt.Errorf("failed to create live test helper (%w)", err))
}
return helper
}
func getHelperMock(t *testing.T) ovirtclient.TestHelper {
helper, err := ovirtclient.NewMockTestHelper(ovirtclientlog.NewTestLogger(t))
if err != nil {
t.Fatal(fmt.Errorf("failed to create mock test helper (%w)", err))
}
return helper
}
func TestMain(m *testing.M) {
flagValueClientMock := "mock"
flagValueClientLive := "live"
flagValueClientAll := "all"
clientFlag := flag.String("client", flagValueClientAll,
"Client to use for running the tests. \n"+
"Supported values: \n"+
fmt.Sprintf("\t%s\t: Run tests with mock client \n", flagValueClientMock)+
fmt.Sprintf("\t%s\t: Run tests with live client \n", flagValueClientLive)+
fmt.Sprintf("\t%s\t: Run tests with mock and live client \n", flagValueClientAll),
)
flag.Parse()
switch *clientFlag {
case flagValueClientLive:
getHelper = getHelperLive
exitVal := m.Run()
os.Exit(exitVal)
case flagValueClientMock:
getHelper = getHelperMock
exitVal := m.Run()
os.Exit(exitVal)
case flagValueClientAll:
getHelper = getHelperMock
exitVal := m.Run()
if exitVal != 0 {
os.Exit(exitVal)
}
getHelper = getHelperLive
exitVal = m.Run()
os.Exit(exitVal)
default:
panic(fmt.Errorf("Unsupported client '%s'", *clientFlag))
}
}