Skip to content

Commit

Permalink
Added username and password attributes for cloud providers (fixes #4)
Browse files Browse the repository at this point in the history
Added username and password attributes for cloud providers

* Removed extra blank line in README

* Formatted code. Added cloud provider checks to tests.

* Updated output.xml with latest input.json.
  • Loading branch information
ryanlevell authored and vania-pooh committed Nov 13, 2017
1 parent 861adb1 commit fd2f45f
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 187 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,20 @@ In **quota** section we define quota names, browser names, their versions and us
}
```
Here **test-quota** is free-form name of the quota, **firefox** is the browser name. Finally **versions** section contains a mapping of browser version to host group name, e.g. **firefox 33.0** will correspond to all hosts defined in **cloud** hosts group.
In **aliases** section we define aliases for quota blocks from **quota** section. For each defined alias quota contents will be copied to a separate file with new name.
In **aliases** section we define aliases for quota blocks from **quota** section. For each defined alias quota contents will be copied to a separate file with new name.

Cloud provider attributes `username` and `password` can be included in the input file:
```
"hosts": {
"cloud-provider": {
"provider-1" : {
"cloud-provider-1.com": {
"port": 4444,
"count": 1,
"username": "user1",
"password": "Password1"
}
}
}
}
```
14 changes: 9 additions & 5 deletions cmd/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import "encoding/xml"
// Input data

type JsonHost struct {
Port int `json:"port"`
Count int `json:"count"`
Port int `json:"port"`
Count int `json:"count"`
Username string `json:"username"`
Password string `json:"password"`
}

type JsonRegion map[string]JsonHost
Expand Down Expand Up @@ -57,7 +59,9 @@ type XmlRegion struct {
}

type XmlHost struct {
Name string `xml:"name,attr"`
Port int `xml:"port,attr"`
Count int `xml:"count,attr"`
Name string `xml:"name,attr"`
Port int `xml:"port,attr"`
Count int `xml:"count,attr"`
Username string `xml:"username,attr,omitempty"`
Password string `xml:"password,attr,omitempty"`
}
8 changes: 5 additions & 3 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ func jsonRegionsToXmlRegions(regions JsonRegions) []XmlRegion {
hostNames := parseHostPattern(hostPattern)
for _, hostName := range hostNames {
xmlHosts = append(xmlHosts, XmlHost{
Name: hostName,
Port: host.Port,
Count: host.Count,
Name: hostName,
Port: host.Port,
Count: host.Count,
Username: host.Username,
Password: host.Password,
})
}
}
Expand Down
48 changes: 36 additions & 12 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cmd

import (
. "github.com/aandryashin/matchers"
"sort"
"testing"
)

func TestParseInputFile(t *testing.T) {
input, err := parseInputFile("../test-data/input.json")
AssertThat(t, err, Is{nil})
AssertThat(t, len(input.Hosts), EqualTo{1})
AssertThat(t, len(input.Hosts), EqualTo{2})
AssertThat(t, len(input.Quota), EqualTo{1})
}

Expand All @@ -31,27 +32,50 @@ func TestConvert(t *testing.T) {
AssertThat(t, browser.DefaultVersion, EqualTo{"33.0"})

versions := browser.Versions
AssertThat(t, len(versions), EqualTo{2})
AssertThat(t, len(versions), EqualTo{3})

sort.Slice(versions, func(i, j int) bool {
return versions[i].Number < versions[j].Number
})

firstVersion := versions[0]
AssertThat(t, firstVersion.Number == "33.0" || firstVersion.Number == "42.0", Is{true})
AssertThat(t, firstVersion.Number == "33.0", Is{true})
secondVersion := versions[1]
if firstVersion.Number == "42.0" {
AssertThat(t, secondVersion.Number, EqualTo{"33.0"})
} else {
AssertThat(t, secondVersion.Number, EqualTo{"42.0"})
}
AssertThat(t, secondVersion.Number == "42.0", Is{true})
thirdVersion := versions[2]
AssertThat(t, thirdVersion.Number == "43.0", Is{true})

regions := firstVersion.Regions
AssertThat(t, len(regions), EqualTo{2})
firstRegion := regions[0]
firstRegions := firstVersion.Regions
AssertThat(t, len(firstRegions), EqualTo{2})
firstRegion := firstRegions[0]
AssertThat(t, firstRegion.Name == "region-a" || firstRegion.Name == "region-b", Is{true})

secondRegion := regions[1]
secondRegion := firstRegions[1]
if firstRegion.Name == "region-a" {
AssertThat(t, secondRegion.Name, EqualTo{"region-b"})
} else {
AssertThat(t, secondRegion.Name, EqualTo{"region-a"})
}
AssertThat(t, len(firstRegion.Hosts), EqualTo{20})
AssertThat(t, len(secondRegion.Hosts), EqualTo{20})

for i := 0; i < len(firstRegion.Hosts); i++ {
firstHost := firstRegion.Hosts[i]
secondHost := secondRegion.Hosts[i]

AssertThat(t, firstHost.Username == "" && secondHost.Username == "", Is{true})
AssertThat(t, firstHost.Password == "" && secondHost.Password == "", Is{true})
}

secondRegions := thirdVersion.Regions
AssertThat(t, len(secondRegions), EqualTo{1})
region := secondRegions[0]
AssertThat(t, region.Name == "provider-1", Is{true})

AssertThat(t, len(region.Hosts), EqualTo{5})

for _, host := range region.Hosts {
AssertThat(t, host.Username, EqualTo{"user1"})
AssertThat(t, host.Password, EqualTo{"Password1"})
}
}
15 changes: 13 additions & 2 deletions test-data/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
"count": 2
}
}
},
"cloud-provider": {
"provider-1" : {
"cloud-provider-[1:5].com": {
"port": 4444,
"count": 1,
"username": "user1",
"password": "Password1"
}
}
}
},

Expand All @@ -22,7 +32,8 @@
"defaultVersion": "33.0",
"versions": {
"33.0": "cloud",
"42.0": "cloud"
"42.0": "cloud",
"43.0": "cloud-provider"
}
}
}
Expand All @@ -31,4 +42,4 @@
"aliases": {
"test-quota": ["another-quota"]
}
}
}
Loading

0 comments on commit fd2f45f

Please sign in to comment.