Skip to content

Commit

Permalink
Develop (#35)
Browse files Browse the repository at this point in the history
* добавлен тест проверки наличия платформы
* Возвращена загрузка релизов с releases.1c.ru, так как ddos-guard отключили
* Исправлено падение теста фильтрации Postgres дистрибутивов
  • Loading branch information
thedemoncat authored Nov 3, 2022
1 parent 4aafefe commit df52078
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dist
pack

/tests/api/1c/http-client.private.env.json
tests/api/1c/http-client.env.json
82 changes: 73 additions & 9 deletions downloader/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const (
Platform83Project = "Platform83"
EDTProject = "DevelopmentTools10"
PostgreSQLProject = "AddCompPostgre"
PostgreSQLProject = "AddCompPostgre"
)
const (
x64re = "(?smU)(?:64-bit|64 бит).*"
Expand Down Expand Up @@ -76,11 +76,55 @@ type VersionFilter interface {
Filter(source []*ProjectVersionInfo) (result []*ProjectVersionInfo)
}

type EdtMatchFilter struct {
filters []*regexp.Regexp
matchOffline bool
matchOfflineRe []*regexp.Regexp
distrRe []*regexp.Regexp
}

type PlatformMatchFilter struct {
filters []*regexp.Regexp
x64bitMatch bool
x64bitRegexp *regexp.Regexp
}
type PostgreSqlMatchFilter struct {
filters []*regexp.Regexp
x64bitMatch bool
x64bitRegexp *regexp.Regexp
}

func (p PostgreSqlMatchFilter) MatchString(source string) bool {
if p.x64bitRegexp.MatchString(source) != p.x64bitMatch {
return false
}

for _, filter := range p.filters {

if ok := filter.MatchString(source); !ok {
return false
}

}

return true
}

func (p *PostgreSqlMatchFilter) build(filters []string) error {
for _, filter := range filters {

val, ok := shortFilters[filter]

if !ok {
return fmt.Errorf("unknown <%s> filter", filter)
}

p.filters = append(p.filters, regexp.MustCompile(val))

}

return nil
}

func GetProjectIDByAlias(alias string) string {

Expand All @@ -98,7 +142,7 @@ func NewFileFilter(project string, filter string) (FileFilter, error) {
case Platform83Project:
return newPlatformMatchFilter(filter)
case PostgreSQLProject:
return newPlatformMatchFilter(filter)
return newPostgreSQLFilter(filter)
case EDTProject:
return newEdtFilter(filter)
default:
Expand All @@ -117,6 +161,33 @@ func NewFileFilterMust(project string, filter string) FileFilter {
return newFilter
}

// [email protected]
// "Дистрибутив СУБД PostgreSQL для Linux x86 (64-bit) (дополнительные модули) одним архивом (DEB)",
// "/version_file?nick=AddCompPostgre&ver=14.1-2.1C&path=AddCompPostgre%5c14_1_2_1C%5cpostgresql_14.1_2.1C_amd64_addon_deb.tar.bz2",
func newPostgreSQLFilter(filter string) (*PostgreSqlMatchFilter, error) {
m := &PostgreSqlMatchFilter{
x64bitMatch: false,
x64bitRegexp: x64Regexp,
}

filters := strings.Split(filter, ".")
filters = removeFromFilter(filters, "x32")

if ok := dry.StringInSlice("x64", filters); ok {
filters = removeFromFilter(filters, "x64")
m.x64bitMatch = true
}

// Для Windows если стоит только фильтр по нему и другого нет, то установим для платформы скачиваем полного дистрибутива
if ok := dry.StringInSlice("win", filters) || dry.StringInSlice("windows", filters); ok && len(filters) == 1 {
filters = append(filters, "full")
}

err := m.build(filters)

return m, err
}

func newPlatformMatchFilter(filter string) (*PlatformMatchFilter, error) {

m := &PlatformMatchFilter{
Expand Down Expand Up @@ -190,13 +261,6 @@ func removeFromFilter(s []string, r string) []string {
return s
}

type EdtMatchFilter struct {
filters []*regexp.Regexp
matchOffline bool
matchOfflineRe []*regexp.Regexp
distrRe []*regexp.Regexp
}

func newEdtFilter(filter string) (*EdtMatchFilter, error) {
m := &EdtMatchFilter{
matchOffline: true,
Expand Down
24 changes: 15 additions & 9 deletions downloader/oneDownloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func Test_filterReleaseFiles(t *testing.T) {
},
},
2,
}, {
},
{
"DevelopmentTools10 with Bellsoft JDK",
args{
list: []ReleaseFileInfo{
Expand All @@ -61,11 +62,12 @@ func Test_filterReleaseFiles(t *testing.T) {
},
},
filters: []FileFilter{
NewFileFilterMust("DevelopmentTools10", "deb"),
NewFileFilterMust(EDTProject, "deb"),
},
},
1,
}, {
},
{
"DevelopmentTools10 with Bellsoft JDK",
args{
list: []ReleaseFileInfo{
Expand All @@ -85,11 +87,12 @@ func Test_filterReleaseFiles(t *testing.T) {
},
},
filters: []FileFilter{
NewFileFilterMust("DevelopmentTools10", "deb"),
NewFileFilterMust(EDTProject, "deb"),
},
},
2,
}, {
},
{
"DevelopmentTools10 only Bellsoft JDK",
args{
list: []ReleaseFileInfo{
Expand All @@ -109,11 +112,12 @@ func Test_filterReleaseFiles(t *testing.T) {
},
},
filters: []FileFilter{
NewFileFilterMust("DevelopmentTools10", "deb.jdk.x64"),
NewFileFilterMust(EDTProject, "deb.jdk.x64"),
},
},
1,
}, {
},
{
"PosqtreSQL with 14.1-2.1C",
args{
list: []ReleaseFileInfo{
Expand Down Expand Up @@ -156,22 +160,24 @@ func TestOnegetDownloader_Platform_getFilesExist(t *testing.T) {
versions := []string{
"8.3.21.1302",
"8.3.21.1302",
"8.3.22.1672",
"8.3.21.1607",
}
for _, ver := range versions {
assert.True(t, releaseExist(t, platform, ver))
}

}

// На текущий момент тест не актуален, так как релизы все доступны
func TestOnegetDownloader_Platform_getFilesNotExist(t *testing.T) {
platform := "Platform83"
// Список существующих платформ
versions := []string{
"8.3.22.1672",
"8.3.21.1607",
}
for _, ver := range versions {
assert.False(t, releaseExist(t, platform, ver))
assert.True(t, releaseExist(t, platform, ver))
}
}

Expand Down

0 comments on commit df52078

Please sign in to comment.