e27381f3af
Much evident on the storagenode dashboard, the minimum version shown is a very old version and that is taken from the deprecated part of version info from the version control server, and we no longer update the deprecated part on the server. This change forces it to use the new sem version, and checks for the old version if the server is probably running an old version of the version control system. Also fixes a bug where the suggested version returned for all processes is taken from the storagenode part. Issue: https://github.com/storj/storj/issues/5673 Change-Id: I57b7358c2826a6e25f441dfa9579a1aef50a7e89
149 lines
3.6 KiB
Go
149 lines
3.6 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package checker_test
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/zap/zaptest"
|
|
|
|
"storj.io/common/testcontext"
|
|
"storj.io/private/version"
|
|
"storj.io/storj/private/version/checker"
|
|
"storj.io/storj/versioncontrol"
|
|
)
|
|
|
|
var testHexSeed = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
|
|
|
|
func TestClient_All(t *testing.T) {
|
|
ctx := testcontext.New(t)
|
|
defer ctx.Cleanup()
|
|
|
|
peer := newTestPeer(t, ctx)
|
|
defer ctx.Check(peer.Close)
|
|
|
|
clientConfig := checker.ClientConfig{
|
|
ServerAddress: "http://" + peer.Addr(),
|
|
RequestTimeout: 0,
|
|
}
|
|
client := checker.New(clientConfig)
|
|
|
|
versions, err := client.All(ctx)
|
|
require.NoError(t, err)
|
|
|
|
processesValue := reflect.ValueOf(&versions.Processes)
|
|
fieldCount := reflect.Indirect(processesValue).NumField()
|
|
|
|
for i := 0; i < fieldCount; i++ {
|
|
field := reflect.Indirect(processesValue).Field(i)
|
|
|
|
versionString := fmt.Sprintf("v%d.%d.%d", i+1, i+2, i+3)
|
|
|
|
process, ok := field.Interface().(version.Process)
|
|
require.True(t, ok)
|
|
require.Equal(t, versionString, process.Minimum.Version)
|
|
require.Equal(t, versionString, process.Suggested.Version)
|
|
}
|
|
}
|
|
|
|
func TestClient_Process(t *testing.T) {
|
|
ctx := testcontext.New(t)
|
|
defer ctx.Cleanup()
|
|
|
|
peer := newTestPeer(t, ctx)
|
|
defer ctx.Check(peer.Close)
|
|
|
|
clientConfig := checker.ClientConfig{
|
|
ServerAddress: "http://" + peer.Addr(),
|
|
RequestTimeout: 0,
|
|
}
|
|
client := checker.New(clientConfig)
|
|
|
|
processesType := reflect.TypeOf(version.Processes{})
|
|
fieldCount := processesType.NumField()
|
|
for i := 0; i < fieldCount; i++ {
|
|
field := processesType.Field(i)
|
|
|
|
expectedVersionStr := fmt.Sprintf("v%d.%d.%d", i+1, i+2, i+3)
|
|
|
|
process, err := client.Process(ctx, field.Name)
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedVersionStr, process.Minimum.Version)
|
|
require.Equal(t, expectedVersionStr, process.Suggested.Version)
|
|
|
|
actualHexSeed := hex.EncodeToString(process.Rollout.Seed[:])
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, testHexSeed, actualHexSeed)
|
|
// TODO: find a better way to test this
|
|
require.NotEmpty(t, process.Rollout.Cursor)
|
|
}
|
|
}
|
|
|
|
func newTestPeer(t *testing.T, ctx *testcontext.Context) *versioncontrol.Peer {
|
|
t.Helper()
|
|
|
|
testVersions := newTestVersions(t)
|
|
serverConfig := &versioncontrol.Config{
|
|
Address: "127.0.0.1:0",
|
|
Versions: versioncontrol.OldVersionConfig{
|
|
Satellite: "v0.0.1",
|
|
Storagenode: "v0.0.1",
|
|
Uplink: "v0.0.1",
|
|
Gateway: "v0.0.1",
|
|
Identity: "v0.0.1",
|
|
},
|
|
Binary: testVersions,
|
|
}
|
|
|
|
return newTestPeerWithConfig(t, ctx, serverConfig)
|
|
}
|
|
|
|
func newTestPeerWithConfig(t *testing.T, ctx *testcontext.Context, config *versioncontrol.Config) *versioncontrol.Peer {
|
|
t.Helper()
|
|
|
|
peer, err := versioncontrol.New(zaptest.NewLogger(t), config)
|
|
require.NoError(t, err)
|
|
|
|
ctx.Go(func() error {
|
|
return peer.Run(ctx)
|
|
})
|
|
|
|
return peer
|
|
}
|
|
|
|
func newTestVersions(t *testing.T) (versions versioncontrol.ProcessesConfig) {
|
|
t.Helper()
|
|
|
|
versionsValue := reflect.ValueOf(&versions)
|
|
versionsElem := versionsValue.Elem()
|
|
fieldCount := versionsElem.NumField()
|
|
|
|
for i := 0; i < fieldCount; i++ {
|
|
field := versionsElem.Field(i)
|
|
|
|
versionString := fmt.Sprintf("v%d.%d.%d", i+1, i+2, i+3)
|
|
binary := versioncontrol.ProcessConfig{
|
|
Minimum: versioncontrol.VersionConfig{
|
|
Version: versionString,
|
|
},
|
|
Suggested: versioncontrol.VersionConfig{
|
|
Version: versionString,
|
|
},
|
|
Rollout: versioncontrol.RolloutConfig{
|
|
Seed: testHexSeed,
|
|
Cursor: 100,
|
|
},
|
|
}
|
|
|
|
field.Set(reflect.ValueOf(binary))
|
|
}
|
|
return versions
|
|
}
|