From 3fc0b9c584e1e475d5a1656fc3bbc300a6211d89 Mon Sep 17 00:00:00 2001 From: thedemoncat Date: Mon, 5 Jul 2021 11:41:01 +0300 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=20=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=B2=D1=80=D0=B0=D1=82=D0=B0=20=D0=BF=D1=83=D1=82=D0=B8=20?= =?UTF-8?q?=D0=BA=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D1=83=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=B0=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commonTestMethods.go | 12 ++++++++++++ mdclasses_test.go | 2 +- mdoTypes.go | 16 +++++++++++++++- mdoTypes_test.go | 38 +++++++++++++++++--------------------- unpack_test.go | 19 +++++++++++++++++++ 5 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 commonTestMethods.go create mode 100644 unpack_test.go diff --git a/commonTestMethods.go b/commonTestMethods.go new file mode 100644 index 00000000..fdc726dc --- /dev/null +++ b/commonTestMethods.go @@ -0,0 +1,12 @@ +package mdclasses + +import "testing" + +func unpackTestConf(t *testing.T) Configuration { + got, err := UnpackConfiguration("tests/metadata/ssl/src") + if err != nil { + t.Errorf("UnpackConfiguration() error = %v", err) + return Configuration{} + } + return got +} diff --git a/mdclasses_test.go b/mdclasses_test.go index c6bb50f5..522b2ce3 100644 --- a/mdclasses_test.go +++ b/mdclasses_test.go @@ -42,7 +42,7 @@ func TestUnpackConfiguration(t *testing.T) { } } -func Test(t *testing.T) { +func TestCompareFile(t *testing.T) { tests := []struct { name string dir string diff --git a/mdoTypes.go b/mdoTypes.go index 0abbf2ae..ff4ffe16 100644 --- a/mdoTypes.go +++ b/mdoTypes.go @@ -90,6 +90,8 @@ func (m MDOType) Group() string { return "ExchangePlans" case EVENT_SUBSCRIPTION: return "EventSubscriptions" + case ROLE: + return "Roles" //case COMMON_MODULE: // return "CommonModules" //case COMMON_MODULE: @@ -226,6 +228,16 @@ func (e MDOTypeRefList) Delete(index int) ([]MDOTypeRef, error) { return e, errors.New(fmt.Sprintf("Error delete object from index %v", index)) } +// Возвращает элемент по имени +func (e MDOTypeRefList) GetByName(name string) (MDOTypeRef, error) { + for _, t := range e { + if t.ref == name { + return t, nil + } + } + return MDOTypeRef{}, errors.Errorf("Нет такого объекта метаданных") +} + func removeElement(list []MDOTypeRef, i int) []MDOTypeRef { if i < len(list)-1 { list = append(list[:i], list[i+1:]...) @@ -323,9 +335,11 @@ func (m MDOTypeRef) IsNull() bool { } func (m MDOTypeRef) Filename() string { - return filepath.Join(m.Dir(), m.ref+ExtMdo) +} +func (m MDOTypeRef) GetPath() string { + return m.Filename() } func (m MDOTypeRef) Dir() string { diff --git a/mdoTypes_test.go b/mdoTypes_test.go index 7e8819bb..cfc663ad 100644 --- a/mdoTypes_test.go +++ b/mdoTypes_test.go @@ -58,11 +58,7 @@ func TestNewMDOTypeRefFromString(t *testing.T) { } func TestMDOTypeRefExist(t *testing.T) { - got, err := UnpackConfiguration("tests/metadata/ssl/src") - if err != nil { - t.Errorf("UnpackConfiguration() error = %v", err) - return - } + got := unpackTestConf(t) subsystem := MDOTypeRef{ mdoType: "Subsystem", ref: "ПерваяПодсистема", @@ -73,11 +69,7 @@ func TestMDOTypeRefExist(t *testing.T) { } func TestMDOTypeRefGetIndex(t *testing.T) { - got, err := UnpackConfiguration("tests/metadata/edt/src") - if err != nil { - t.Errorf("UnpackConfiguration() error = %v", err) - return - } + got := unpackTestConf(t) mdo := MDOTypeRef{ mdoType: "Subsystem", ref: "ВтораяПодсистема", @@ -86,17 +78,13 @@ func TestMDOTypeRefGetIndex(t *testing.T) { } index := got.ConfigurationChildObjects.Subsystems.GetIndex(mdo) if index < 0 { - t.Errorf("Ошибка поиска дочернего объекта = %v", err) + t.Errorf("Ошибка поиска дочернего объекта = %s", mdo.ref) } require.True(t, index == 1) } func TestMDOTypeRefDelete(t *testing.T) { - got, err := UnpackConfiguration("tests/metadata/edt/src") - if err != nil { - t.Errorf("UnpackConfiguration() error = %v", err) - return - } + got := unpackTestConf(t) ref := got.ConfigurationChildObjects.Subsystems newChild, err := ref.Delete(1) if err != nil { @@ -107,13 +95,21 @@ func TestMDOTypeRefDelete(t *testing.T) { } func TestMDOTypeRefCreate(t *testing.T) { - got, err := UnpackConfiguration("tests/metadata/edt/src") - if err != nil { - t.Errorf("UnpackConfiguration() error = %v", err) - return - } + got := unpackTestConf(t) MDOTypeRef := NewMDOTypeRefFromString("Subsystem.NewSubsystem") got.ConfigurationChildObjects.Subsystems = append(got.ConfigurationChildObjects.Subsystems, MDOTypeRef) require.True(t, true) } + +func TestGetFilename(t *testing.T) { + config := UnpackConfig{ + Base: "tests/metadata/ssl", + Path: "tests/metadata/ssl", + } + path, err := config.getFilename("EventSubscription.АвтономнаяРаботаПроверитьВозможностьЗаписиОбщихДанных") + if err != nil { + t.Errorf("Ошибка получения пути к файлу %s", err) + } + require.True(t, path == "") +} diff --git a/unpack_test.go b/unpack_test.go new file mode 100644 index 00000000..0f58ef47 --- /dev/null +++ b/unpack_test.go @@ -0,0 +1,19 @@ +package mdclasses + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +// Тест, возвращающий путь к объекту метаданных относитьельно каталога исходников +func TestGetPathToObject(t *testing.T) { + got := unpackTestConf(t) + + mdoType := got.ConfigurationChildObjects.Roles + role, err := mdoType.GetByName("АдминистраторСистемы") + if err != nil { + + } + path := role.Filename() + require.True(t, path == "Roles\\АдминистраторСистемы\\АдминистраторСистемы.mdo") +}