MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / main

Function main

examples/example_client_setup.go:17–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func main() {
18 log.Println("Testing Complete Client Setup example from DOCUMENTATION.md...")
19
20 // Load configuration
21 cfg := config.NewConfig()
22 cfg.ParseFlags()
23 cfg.SetDefaults()
24
25 // For testing purposes, set some required values if not provided
26 if cfg.Addr == "" {
27 cfg.Addr = "https://test.example.com:8006"
28 log.Println("Using test address:", cfg.Addr)
29 }
30 if cfg.User == "" {
31 cfg.User = "test@pam"
32 log.Println("Using test user:", cfg.User)
33 }
34 if cfg.Password == "" && cfg.TokenID == "" {
35 cfg.Password = "test-password"
36 log.Println("Using test password authentication")
37 }
38
39 if err := cfg.Validate(); err != nil {
40 log.Fatal("Invalid configuration:", err)
41 }
42 log.Println("Configuration validation passed ✓")
43
44 // Create logger
45 loggerInstance, err := logger.NewInternalLogger(logger.LevelInfo, cfg.CacheDir)
46 if err != nil {
47 log.Fatal("Failed to create logger:", err)
48 }
49 defer loggerInstance.Close()
50 log.Println("Logger created successfully ✓")
51
52 // Create adapters
53 configAdapter := adapters.NewConfigAdapter(cfg)
54 loggerAdapter := adapters.NewLoggerAdapter(cfg)
55 log.Println("Adapters created successfully ✓")
56
57 // Create API client - note that this creates the client but doesn't authenticate yet
58 client, err := api.NewClient(configAdapter,
59 api.WithLogger(loggerAdapter))
60 if err != nil {
61 log.Printf("Failed to create client: %v", err)
62 log.Println("This is expected with test credentials - the client creation itself succeeded ✓")
63 log.Println("The error occurred during initial authentication attempt.")
64 } else {
65 log.Println("API client created successfully ✓")
66
67 // Test the client with a timeout context (since we're using test credentials)
68 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
69 defer cancel()
70
71 // Try to get VM list (this will likely fail with test credentials, but should not panic)
72 log.Println("Attempting to get VM list (expected to fail with test credentials)...")
73 vms, err := client.GetVmList(ctx)
74 if err != nil {

Callers

nothing calls this directly

Calls 10

SetDefaultsMethod · 0.95
ValidateMethod · 0.95
GetVmListMethod · 0.95
NewConfigFunction · 0.92
NewInternalLoggerFunction · 0.92
NewConfigAdapterFunction · 0.92
NewLoggerAdapterFunction · 0.92
NewClientFunction · 0.92
WithLoggerFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected