Skip to content

Commit

Permalink
Merge branch 'feature/DEVOPS-2327-diversity-zone-filtering' into 'mas…
Browse files Browse the repository at this point in the history
…ter'

# 0.1.14 Release

See merge request opensource/megaportgo!40
  • Loading branch information
Daniel Barnes committed Feb 20, 2023
1 parent 403bb44 commit ca67556
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.1.14 Release

## New Features
- Support for filtering Partner Megaports by Diversity Zone.

# 0.1.13 Release

## New Features
Expand Down
31 changes: 31 additions & 0 deletions service/partner/partner.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,34 @@ func (p *Partner) FilterPartnerMegaportByLocationId(partnerMegaports *[]types.Pa
return nil
}
}

func (p *Partner) FilterPartnerMegaportByDiversityZone(partnerMegaports *[]types.PartnerMegaport, diversityZone string, exactMatch bool) error {
existingMegaports := *partnerMegaports
var filteredMegaports []types.PartnerMegaport

for i := 0; i < len(existingMegaports); i++ {
match := false

if diversityZone != "" {
if exactMatch { // Exact Match
if diversityZone == existingMegaports[i].DiversityZone {
match = true
}
}
} else {
match = true
}

if match && existingMegaports[i].VXCPermitted {
filteredMegaports = append(filteredMegaports, existingMegaports[i])
}
}

*partnerMegaports = filteredMegaports

if len(*partnerMegaports) == 0 {
return errors.New(mega_err.ERR_PARTNER_PORT_NO_RESULTS)
} else {
return nil
}
}
13 changes: 13 additions & 0 deletions service/partner/partner_integ_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build integration
// +build integration

// Copyright 2020 Megaport Pty Ltd
Expand Down Expand Up @@ -150,6 +151,18 @@ func TestFilterPartnerMegaportByProductName(t *testing.T) {
}
}

func TestFilterPartnerMegaportByDiversityZone(t *testing.T) {
assert := assert.New(t)
partner := New(&cfg)

partnerMegaports, _ := partner.GetAllPartnerMegaports()
partner.FilterPartnerMegaportByDiversityZone(&partnerMegaports, "red", true)

for i := 0; i < len(partnerMegaports); i++ {
assert.Equal(partnerMegaports[i].DiversityZone, "red")
}
}

/*
func TestGetPartnerMegaportByFilter(t *testing.T) {
// 52dfc422-9041-4a16-b040-f03c795a3e01
Expand Down
19 changes: 10 additions & 9 deletions types/partner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
package types

type PartnerMegaport struct {
ConnectType string `json:"connectType"`
ProductUID string `json:"productUid"`
ProductName string `json:"title"`
CompanyUID string `json:"companyUid"`
CompanyName string `json:"companyName"`
LocationId int `json:"locationId"`
Speed int `json:"speed"`
Rank int `json:"rank"`
VXCPermitted bool `json:"vxcPermitted"`
ConnectType string `json:"connectType"`
ProductUID string `json:"productUid"`
ProductName string `json:"title"`
CompanyUID string `json:"companyUid"`
CompanyName string `json:"companyName"`
DiversityZone string `json:"diversityZone"`
LocationId int `json:"locationId"`
Speed int `json:"speed"`
Rank int `json:"rank"`
VXCPermitted bool `json:"vxcPermitted"`
}

0 comments on commit ca67556

Please sign in to comment.