Skip to content

Commit

Permalink
тест возврата пути к объекту метаданных
Browse files Browse the repository at this point in the history
  • Loading branch information
thedemoncat committed Jul 5, 2021
1 parent 7a7103f commit 3fc0b9c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 23 deletions.
12 changes: 12 additions & 0 deletions commonTestMethods.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion mdclasses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion mdoTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:]...)
Expand Down Expand Up @@ -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 {
Expand Down
38 changes: 17 additions & 21 deletions mdoTypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "ПерваяПодсистема",
Expand All @@ -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: "ВтораяПодсистема",
Expand All @@ -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 {
Expand All @@ -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 == "")
}
19 changes: 19 additions & 0 deletions unpack_test.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 3fc0b9c

Please sign in to comment.