-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathexample_test.go
More file actions
43 lines (35 loc) · 1.29 KB
/
example_test.go
File metadata and controls
43 lines (35 loc) · 1.29 KB
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
package buildkite_test
import (
"github.com/buildkite/go-buildkite/v4"
)
// Example_clientOptComposition demonstrates how to programmatically compose client options
// based on conditional logic, leveraging the exported ClientOpt type.
func Example_clientOptComposition() {
// This is a test example only - we don't actually run the client
// Simulating command-line flags or config values
baseURL := "https://api.buildkite.com/"
token := "your-token"
userAgentFlag := "custom-agent" // Could be empty in some cases
debugEnabled := false
// Build options programmatically - we're testing the pattern more than actual execution
var opts []buildkite.ClientOpt
// Conditionally add other options
if baseURL != buildkite.DefaultBaseURL {
opts = append(opts, buildkite.WithBaseURL(baseURL))
}
if userAgentFlag != "" {
opts = append(opts, buildkite.WithUserAgent(userAgentFlag))
}
if debugEnabled {
opts = append(opts, buildkite.WithHTTPDebug(true))
}
// Always add required options
opts = append(opts, buildkite.WithTokenAuth(token))
// Create the client using the composed options
client, err := buildkite.NewClient(opts...)
if err != nil {
// In a real application, you'd handle this error appropriately
// For this example, we'll just acknowledge the client was created
_ = client
}
}