2019-10-20 08:56:23 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package checker_test
|
|
|
|
|
|
|
|
import (
|
2019-10-21 11:50:59 +01:00
|
|
|
"encoding/hex"
|
2019-10-20 08:56:23 +01:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap/zaptest"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/version"
|
|
|
|
"storj.io/storj/internal/version/checker"
|
2019-10-21 11:50:59 +01:00
|
|
|
"storj.io/storj/pkg/storj"
|
2019-10-20 08:56:23 +01:00
|
|
|
"storj.io/storj/versioncontrol"
|
|
|
|
)
|
|
|
|
|
2019-10-21 11:50:59 +01:00
|
|
|
var testHexSeed = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
|
|
|
|
|
2019-10-20 08:56:23 +01:00
|
|
|
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)
|
2019-10-21 11:50:59 +01:00
|
|
|
|
|
|
|
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 TestClient_ShouldUpdate(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 := 1; i < fieldCount; i++ {
|
|
|
|
field := processesType.Field(i - 1)
|
|
|
|
|
|
|
|
expectedVersionStr := fmt.Sprintf("v%d.%d.%d", i, i+1, i+2)
|
|
|
|
|
|
|
|
// NB: test cursor is 100%; rollout/nodeID should-update calculation is tested elsewhere.
|
|
|
|
shouldUpdate, ver, err := client.ShouldUpdate(ctx, field.Name, storj.NodeID{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, shouldUpdate)
|
|
|
|
require.Equal(t, expectedVersionStr, ver.Version)
|
2019-10-20 08:56:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTestPeer(t *testing.T, ctx *testcontext.Context) *versioncontrol.Peer {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
testVersions := newTestVersions(t)
|
|
|
|
serverConfig := &versioncontrol.Config{
|
|
|
|
Address: "127.0.0.1:0",
|
2019-10-21 11:50:59 +01:00
|
|
|
Versions: versioncontrol.OldVersionConfig{
|
2019-10-20 08:56:23 +01:00
|
|
|
Satellite: "v0.0.1",
|
|
|
|
Storagenode: "v0.0.1",
|
|
|
|
Uplink: "v0.0.1",
|
|
|
|
Gateway: "v0.0.1",
|
|
|
|
Identity: "v0.0.1",
|
|
|
|
},
|
|
|
|
Binary: testVersions,
|
|
|
|
}
|
|
|
|
peer, err := versioncontrol.New(zaptest.NewLogger(t), serverConfig)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ctx.Go(func() error {
|
|
|
|
return peer.Run(ctx)
|
|
|
|
})
|
|
|
|
|
|
|
|
return peer
|
|
|
|
}
|
|
|
|
|
2019-10-21 11:50:59 +01:00
|
|
|
func newTestVersions(t *testing.T) (versions versioncontrol.ProcessesConfig) {
|
2019-10-20 08:56:23 +01:00
|
|
|
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)
|
2019-10-21 11:50:59 +01:00
|
|
|
binary := versioncontrol.ProcessConfig{
|
|
|
|
Minimum: versioncontrol.VersionConfig{
|
2019-10-20 08:56:23 +01:00
|
|
|
Version: versionString,
|
|
|
|
},
|
2019-10-21 11:50:59 +01:00
|
|
|
Suggested: versioncontrol.VersionConfig{
|
2019-10-20 08:56:23 +01:00
|
|
|
Version: versionString,
|
|
|
|
},
|
2019-10-21 11:50:59 +01:00
|
|
|
Rollout: versioncontrol.RolloutConfig{
|
|
|
|
Seed: testHexSeed,
|
|
|
|
Cursor: 100,
|
|
|
|
},
|
2019-10-20 08:56:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
field.Set(reflect.ValueOf(binary))
|
|
|
|
}
|
|
|
|
return versions
|
|
|
|
}
|