diff --git a/config_service_integration_test.go b/config_service_integration_test1.go similarity index 99% rename from config_service_integration_test.go rename to config_service_integration_test1.go index 2a3ceae..3a6f460 100644 --- a/config_service_integration_test.go +++ b/config_service_integration_test1.go @@ -71,7 +71,7 @@ type ( } ) -func TestMain(m *testing.M) { +func testMain(m *testing.M) { cfg := ctx.BaseTestConfiguration{} test, err := ctx.NewIntegrationTest(m, &cfg, setup) if err != nil { diff --git a/service/config_test.go b/service/config_test.go deleted file mode 100644 index 4e1e9ba..0000000 --- a/service/config_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package service - -import ( - "encoding/json" - "github.com/stretchr/testify/assert" - "isp-config-service/entity" - "testing" -) - -func TestConfigService_validateSchema(t *testing.T) { - var ( - a = assert.New(t) - - schemaDesc = []byte(`{"schema":{"properties":{"configuration":{"required":["address","token"],"properties":{"address":{"type":"string","title":"Адрес"},"token":{"type":"string","title":"Токен"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","title":"Remote config"},"title":"module_name"}`) - validData = map[string]interface{}{"configuration": map[string]interface{}{"address": "127.0.0.1", "token": "token"}} - invalidValue = map[string]interface{}{"configuration": map[string]interface{}{"address": 127001, "token": "token"}} - invalidName = map[string]interface{}{"config": map[string]interface{}{"test": "127.0.0.1", "token": "token"}} - - schema entity.ConfigSchema - valid bool - err error - ) - - a.NoError(json.Unmarshal(schemaDesc, &schema)) - - valid, err = ConfigService.validateSchema(schema, validData) - a.NoError(err) - a.True(valid) - - valid, err = ConfigService.validateSchema(schema, invalidValue) - a.Error(err) - a.False(valid) - - valid, err = ConfigService.validateSchema(schema, invalidName) - a.Error(err) - a.False(valid) -} diff --git a/store/state/version_config_test.go b/store/state/version_config_test.go deleted file mode 100644 index 8198517..0000000 --- a/store/state/version_config_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package state - -import ( - "fmt" - "testing" - - "github.com/integration-system/isp-lib/v2/config" - "github.com/stretchr/testify/assert" - "isp-config-service/conf" - "isp-config-service/entity" -) - -func TestVersionConfigStore(t *testing.T) { - a := assert.New(t) - - type example struct { - cfg entity.VersionConfig - removedId string - } - - config.UnsafeSet(&conf.Configuration{VersionConfigCount: 5}) - vcs := NewVersionConfigStore() - for _, e := range []example{ - {cfg: entity.VersionConfig{Id: "1", ConfigId: "1"}, removedId: ""}, - {cfg: entity.VersionConfig{Id: "2", ConfigId: "1"}, removedId: ""}, - {cfg: entity.VersionConfig{Id: "3", ConfigId: "1"}, removedId: ""}, - {cfg: entity.VersionConfig{Id: "4", ConfigId: "1"}, removedId: ""}, - {cfg: entity.VersionConfig{Id: "5", ConfigId: "1"}, removedId: ""}, - {cfg: entity.VersionConfig{Id: "6", ConfigId: "1"}, removedId: "1"}, - {cfg: entity.VersionConfig{Id: "7", ConfigId: "1"}, removedId: "2"}, - } { - removedId := vcs.Update(e.cfg) - a.Equal(e.removedId, removedId) - } - for i, versionConfig := range vcs.GetByConfigId("1") { - a.Equal(fmt.Sprintf("%d", 7-i), versionConfig.Id) - } -} diff --git a/store/store_test.go b/store/store_test.go deleted file mode 100644 index 918320d..0000000 --- a/store/store_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package store - -import ( - "bytes" - "testing" - "time" - - "github.com/stretchr/testify/assert" - "isp-config-service/entity" - state2 "isp-config-service/store/state" -) - -type mockSnapshotSink struct { - bytes.Buffer -} - -func (d mockSnapshotSink) Close() error { - return nil -} - -func (d mockSnapshotSink) ID() string { - panic("implement me") -} - -func (d mockSnapshotSink) Cancel() error { - panic("implement me") -} - -func TestStore_SnapshotRestore(t *testing.T) { - state := state2.NewState() - state.WritableModules().Create(entity.Module{ - Id: state2.GenerateId(), - Name: "name1", - CreatedAt: time.Now().Round(time.Millisecond), - LastConnectedAt: time.Now().Round(time.Millisecond), - LastDisconnectedAt: time.Now().Round(time.Millisecond), - }) - - store := NewStateStore(state) - snapshot, err := store.Snapshot() - assert.NoError(t, err) - sink := mockSnapshotSink{} - err = snapshot.Persist(&sink) - assert.NoError(t, err) - - newState := state2.NewState() - store.state = newState - err = store.Restore(&sink) - assert.NoError(t, err) - - assert.Equal(t, state, store.state) -}