forked from kubeshop/tracetest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
66 lines (50 loc) · 1.33 KB
/
version.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
package actions
import (
"context"
"fmt"
"github.com/kubeshop/tracetest/cli/config"
)
type VersionConfig struct{}
type versionAction struct {
actionAgs
}
var _ Action[VersionConfig] = &versionAction{}
func NewGetServerVersionAction(options ...ActionArgsOption) versionAction {
args := NewActionArgs(options...)
return versionAction{actionAgs: args}
}
func (a versionAction) Run(ctx context.Context, args VersionConfig) error {
versionText, _ := a.GetVersion(ctx)
fmt.Println(versionText)
return nil
}
func (a versionAction) GetVersion(ctx context.Context) (string, bool) {
result := fmt.Sprintf(`CLI: %s`, config.Version)
if a.config.IsEmpty() {
return result + `
Server: Not Configured`, false
}
version, err := a.GetServerVersion(ctx)
if err != nil {
return result + fmt.Sprintf(`
Server: Failed to get the server version - %s`, err.Error()), false
}
isVersionMatch := version == config.Version
if isVersionMatch {
version += `
✔️ Version match`
}
return result + fmt.Sprintf(`
Server: %s`, version), isVersionMatch
}
func (a versionAction) GetServerVersion(ctx context.Context) (string, error) {
if a.config.IsEmpty() {
return "", fmt.Errorf("not Configured")
}
req := a.client.ApiApi.GetVersion(ctx)
version, _, err := req.Execute()
if err != nil {
return "", err
}
return *version.Version, nil
}