Skip to content

Commit

Permalink
Set base as Default when there is no default is selected (TykTechnolo…
Browse files Browse the repository at this point in the history
  • Loading branch information
furkansenharputlu authored Jan 11, 2022
1 parent 0f406bb commit 0554588
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions apidef/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (a *APIDefinition) MigrateVersioning() (versions []APIDefinition, err error
var found bool
if baseVInfo, found = a.VersionData.Versions[base]; !found {
a.VersionDefinition.Default = ""

if baseVInfo, found = a.VersionData.Versions["Default"]; !found {
base = "Default"
if baseVInfo, found = a.VersionData.Versions[base]; !found {
var sortedVersionNames []string
for vName := range a.VersionData.Versions {
sortedVersionNames = append(sortedVersionNames, vName)
Expand Down
27 changes: 16 additions & 11 deletions apidef/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ import (
)

const (
dbID = "dbID"
apiID = "apiID"
listenPath = "listenPath"
baseTarget = "base.com"
v1Target = "v1.com"
v2Target = "v2.com"
v1 = "v1"
v2 = "v2"
exp1 = "exp1"
exp2 = "exp2"
key = "version"
dbID = "dbID"
apiID = "apiID"
listenPath = "listenPath"
baseTarget = "base.com"
baseAPIName = "base-api"
v1Target = "v1.com"
v2Target = "v2.com"
v1 = "v1"
v2 = "v2"
exp1 = "exp1"
exp2 = "exp2"
key = "version"
)

var testV1ExtendedPaths = ExtendedPathsSet{
Expand All @@ -37,6 +38,7 @@ func oldTestAPI() APIDefinition {
return APIDefinition{
Id: dbID,
APIID: apiID,
Name: baseAPIName,
Active: true,
Proxy: ProxyConfig{TargetURL: baseTarget, ListenPath: listenPath},
VersionDefinition: VersionDefinition{
Expand Down Expand Up @@ -211,6 +213,9 @@ func TestAPIDefinition_MigrateVersioning_DefaultEmpty(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, expectedBaseData, base.VersionData)

assert.Len(t, versions, 1)
assert.Contains(t, versions[0].Name, baseAPIName+"-Alpha")
})
}

Expand Down

0 comments on commit 0554588

Please sign in to comment.