/
setup.go
64 lines (51 loc) · 1.61 KB
/
setup.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
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-Present Datadog, Inc.
package xtesting
import (
"net/url"
"testing"
"github.com/DataDog/cloudcraft-go"
)
const _envAPIKey string = "CLOUDCRAFT_TEST_API_KEY"
// SetupMockClient sets up a test API client for unit tests against a mock
// version of the Cloudcraft API.
func SetupMockClient(t *testing.T, endpoint *url.URL) *cloudcraft.Client {
t.Helper()
cfg := &cloudcraft.Config{
Scheme: endpoint.Scheme,
Host: endpoint.Hostname(),
Port: endpoint.Port(),
Path: cloudcraft.DefaultPath,
Key: "not-a-real-key-oRbwhd5RTvWsPJ89ZkASHU13qcyd=",
}
client, err := cloudcraft.NewClient(cfg)
if err != nil {
t.Fatalf("failed to create client for mock tests: %v", err)
}
return client
}
// SetupLiveClient sets up a test API client for unit tests against the live
// Cloudcraft API.
//
// The following environment variables are required:
// - CLOUDCRAFT_TEST_API_KEY
//
// If any of these variables are not set, SetupLiveClient will fail the test.
func SetupLiveClient(t *testing.T) *cloudcraft.Client {
t.Helper()
key := GetEnv(t, _envAPIKey)
cfg := &cloudcraft.Config{
Scheme: cloudcraft.DefaultScheme,
Host: cloudcraft.DefaultHost,
Port: cloudcraft.DefaultPort,
Path: cloudcraft.DefaultPath,
MaxRetries: 8,
Key: key,
}
client, err := cloudcraft.NewClient(cfg)
if err != nil {
t.Fatalf("failed to create client for live tests: %v", err)
}
return client
}