mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 23:16:52 +00:00
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:
19
config/versions/v0/v0.go
Normal file
19
config/versions/v0/v0.go
Normal 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
|
||||
}
|
||||
26
config/versions/v0/v0_test.go
Normal file
26
config/versions/v0/v0_test.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user