-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
106 lines (91 loc) · 3.51 KB
/
main.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
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
97
98
99
100
101
102
103
104
105
106
package main
import (
_ "embed"
"flag"
e2e "github.com/newrelic/newrelic-integration-e2e-action/internal"
"github.com/newrelic/newrelic-integration-e2e-action/internal/newrelic"
"github.com/newrelic/newrelic-integration-e2e-action/internal/runtime"
"github.com/sirupsen/logrus"
)
const (
flagSpecPath = "spec_path"
flagVerboseMode = "verbose_mode"
flagApiKey = "api_key"
flagAccountID = "account_id"
flagLicenseKey = "license_key"
flagAgentEnabled = "agent_enabled"
flagRetryAttempts = "retry_attempts"
flagRetrySecons = "retry_seconds"
flagCommitSha = "commit_sha"
flagRegion = "region"
flagScenarioTag = "scenario_tag"
)
func processCliArgs() (string, string, bool, string, int, int, int, string, logrus.Level, string, string) {
specsPath := flag.String(flagSpecPath, "", "Path to the spec file")
licenseKey := flag.String(flagLicenseKey, "", "New Relic License Key")
agentEnabled := flag.Bool(flagAgentEnabled, true, "If false the agent is not run")
verboseMode := flag.Bool(flagVerboseMode, false, "If true the debug level is enabled")
apiKey := flag.String(flagApiKey, "", "New Relic Api Key")
accountID := flag.Int(flagAccountID, 0, "New Relic accountID to be used")
retryAttempts := flag.Int(flagRetryAttempts, 15, "Number of attempts to retry a test")
retrySeconds := flag.Int(flagRetrySecons, 60, "Number of seconds before retrying a test")
commitSha := flag.String(flagCommitSha, "", "Current commit sha")
region := flag.String(flagRegion, "", "Current commit sha")
scenarioTag := flag.String(flagScenarioTag, "", "E2e testing scenario tag")
flag.Parse()
if *licenseKey == "" {
logrus.Fatalf("missing required license_key")
}
if *specsPath == "" {
logrus.Fatalf("missing required spec_path")
}
if *accountID == 0 {
logrus.Fatalf("missing required accountID")
}
if *apiKey == "" {
logrus.Fatalf("missing required apiKey")
}
logLevel := logrus.InfoLevel
if *verboseMode {
logLevel = logrus.DebugLevel
}
return *licenseKey, *specsPath, *agentEnabled, *apiKey, *accountID, *retryAttempts, *retrySeconds, *commitSha, logLevel, *region, *scenarioTag
}
func main() {
logrus.Info("running e2e")
licenseKey, specsPath, agentEnabled, apiKey, accountID, retryAttempts, retrySeconds, commitSha, logLevel, region, scenarioTag := processCliArgs()
s, err := e2e.NewSettings(
e2e.SettingsWithSpecPath(specsPath),
e2e.SettingsWithLogLevel(logLevel),
e2e.SettingsWithLicenseKey(licenseKey),
e2e.SettingsWithAgentEnabled(agentEnabled),
e2e.SettingsWithApiKey(apiKey),
e2e.SettingsWithAccountID(accountID),
e2e.SettingsWithRetryAttempts(retryAttempts),
e2e.SettingsWithRetrySeconds(retrySeconds),
e2e.SettingsWithCommitSha(commitSha),
e2e.SettingsWithRegion(region),
e2e.SettingsWithScenarioTag(scenarioTag),
)
if err != nil {
logrus.Fatalf("error loading settings: %s", err)
}
runner, err := createRunner(s)
if err != nil {
logrus.Fatal(err)
}
if err := runner.Run(); err != nil {
logrus.Fatal(err)
}
logrus.Info("execution completed successfully!")
}
func createRunner(settings e2e.Settings) (*runtime.Runner, error) {
settings.Logger().Debug("validating the spec definition")
nrClient := newrelic.NewNrClient(settings.ApiKey(), settings.Region(), settings.AccountID())
runtimeTester := []runtime.Tester{
runtime.NewEntitiesTester(nrClient, settings.Logger()),
runtime.NewMetricsTester(nrClient, settings.Logger(), settings.SpecParentDir()),
runtime.NewNRQLTester(nrClient, settings.Logger()),
}
return runtime.NewRunner(runtimeTester, settings), nil
}