Config: Refactor version packages (#1887)

* Config: Move config versions to separate pacakges

* Config: Move version tests to blackbox texts

* Config: Protect registerVersion from overflow

* Config: Protect against version already registered
This commit is contained in:
Gareth Kirwan
2025-04-22 04:13:01 +02:00
committed by GitHub
parent 545fa9d01a
commit 1bf3433d61
19 changed files with 254 additions and 153 deletions

19
config/versions/v0/v0.go Normal file
View File

@@ -0,0 +1,19 @@
package v0
import (
"context"
)
// Version is a baseline version with no changes, so we can downgrade back to nothing
// It does not implement any upgrade interfaces
type Version struct{}
// UpgradeConfig is an empty stub
func (*Version) UpgradeConfig(_ context.Context, j []byte) ([]byte, error) {
return j, nil
}
// DowngradeConfig is an empty stub
func (*Version) DowngradeConfig(_ context.Context, j []byte) ([]byte, error) {
return j, nil
}

View File

@@ -0,0 +1,26 @@
package v0_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v0 "github.com/thrasher-corp/gocryptotrader/config/versions/v0"
)
func TestUpgradeConfig(t *testing.T) {
t.Parallel()
in := []byte(`{"untouched":true}`)
out, err := new(v0.Version).UpgradeConfig(context.Background(), in)
require.NoError(t, err)
assert.Equal(t, in, out)
}
func TestDowngradeConfig(t *testing.T) {
t.Parallel()
in := []byte(`{"untouched":true}`)
out, err := new(v0.Version).DowngradeConfig(context.Background(), in)
require.NoError(t, err)
assert.Equal(t, in, out)
}