Upgrade to ReachView v2.24.0
This commit is contained in:
17
emlid/common/client.go
Normal file
17
emlid/common/client.go
Normal file
@ -0,0 +1,17 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
||||
// Client is a ReachRS Updater client
|
||||
type Client struct {
|
||||
*emlid.Client
|
||||
}
|
||||
|
||||
// NewClient returns a new ReachRS ReachView client
|
||||
func NewClient(opts ...emlid.OptionFunc) *Client {
|
||||
return &Client{
|
||||
Client: emlid.NewClient(opts...),
|
||||
}
|
||||
}
|
51
emlid/common/handle_version.go
Normal file
51
emlid/common/handle_version.go
Normal file
@ -0,0 +1,51 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type VersionHandlerFunc func(ctx context.Context, version string, stable bool) error
|
||||
|
||||
type VersionHandler struct {
|
||||
Range string
|
||||
Handler VersionHandlerFunc
|
||||
}
|
||||
|
||||
func NewVersionHandler(versionRange string, h VersionHandlerFunc) *VersionHandler {
|
||||
return &VersionHandler{
|
||||
Range: versionRange,
|
||||
Handler: h,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) HandleVersion(ctx context.Context, handlers ...*VersionHandler) error {
|
||||
rawVersion, stable, err := c.ReachViewVersion(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not retrieve reachview version")
|
||||
}
|
||||
|
||||
version, err := semver.ParseTolerant(rawVersion)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not parse reachview version")
|
||||
}
|
||||
|
||||
for _, h := range handlers {
|
||||
versionRange, err := semver.ParseRange(h.Range)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not parse handler version range")
|
||||
}
|
||||
|
||||
if !versionRange(version) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := h.Handler(ctx, rawVersion, stable); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
26
emlid/common/reachview_version.go
Normal file
26
emlid/common/reachview_version.go
Normal file
@ -0,0 +1,26 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
eventGetReachViewVersion = "get reachview version"
|
||||
eventReachViewVersionResults = "current reachview version"
|
||||
)
|
||||
|
||||
type reachViewVersion struct {
|
||||
Version string `json:"version"`
|
||||
Stable bool `json:"bool"`
|
||||
}
|
||||
|
||||
// ReachViewVersion returns the ReachRS module ReachView version
|
||||
func (c *Client) ReachViewVersion(ctx context.Context) (string, bool, error) {
|
||||
res := &reachViewVersion{}
|
||||
if err := c.ReqResp(ctx, eventGetReachViewVersion, nil, eventReachViewVersionResults, res); err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
return strings.TrimSpace(res.Version), res.Stable, nil
|
||||
}
|
39
emlid/common/reachview_version_test.go
Normal file
39
emlid/common/reachview_version_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
||||
func TestClientReachViewVersion(t *testing.T) {
|
||||
|
||||
if !*runCommonIntegrationTests {
|
||||
t.Skip("To run this test, use: go test -updater-integration")
|
||||
}
|
||||
|
||||
client := NewClient(
|
||||
emlid.WithStandardLogger(),
|
||||
emlid.WithEndpoint(*reachHost, 80),
|
||||
)
|
||||
if err := client.Connect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
version, _, err := client.ReachViewVersion(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if version == "" {
|
||||
t.Error("version should not be empty")
|
||||
}
|
||||
|
||||
defer client.Close()
|
||||
|
||||
}
|
13
emlid/common/util_test.go
Normal file
13
emlid/common/util_test.go
Normal file
@ -0,0 +1,13 @@
|
||||
package common
|
||||
|
||||
import "flag"
|
||||
|
||||
var runCommonIntegrationTests = flag.Bool(
|
||||
"common-integration", false,
|
||||
"Run the 'Common' integration tests (in addition to the unit tests)",
|
||||
)
|
||||
|
||||
var reachHost = flag.String(
|
||||
"reach-host", "192.168.42.1",
|
||||
"The Reach module host to use in integration tests",
|
||||
)
|
Reference in New Issue
Block a user