Skip to content

Commit fd2f45f

Browse files
ryanlevellvania-pooh
authored andcommitted
Added username and password attributes for cloud providers (fixes #4)
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.
1 parent 861adb1 commit fd2f45f

File tree

6 files changed

+173
-187
lines changed

6 files changed

+173
-187
lines changed

README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,20 @@ In **quota** section we define quota names, browser names, their versions and us
7474
}
7575
```
7676
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.
77-
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.
77+
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.
78+
79+
Cloud provider attributes `username` and `password` can be included in the input file:
80+
```
81+
"hosts": {
82+
"cloud-provider": {
83+
"provider-1" : {
84+
"cloud-provider-1.com": {
85+
"port": 4444,
86+
"count": 1,
87+
"username": "user1",
88+
"password": "Password1"
89+
}
90+
}
91+
}
92+
}
93+
```

cmd/data.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import "encoding/xml"
55
// Input data
66

77
type JsonHost struct {
8-
Port int `json:"port"`
9-
Count int `json:"count"`
8+
Port int `json:"port"`
9+
Count int `json:"count"`
10+
Username string `json:"username"`
11+
Password string `json:"password"`
1012
}
1113

1214
type JsonRegion map[string]JsonHost
@@ -57,7 +59,9 @@ type XmlRegion struct {
5759
}
5860

5961
type XmlHost struct {
60-
Name string `xml:"name,attr"`
61-
Port int `xml:"port,attr"`
62-
Count int `xml:"count,attr"`
62+
Name string `xml:"name,attr"`
63+
Port int `xml:"port,attr"`
64+
Count int `xml:"count,attr"`
65+
Username string `xml:"username,attr,omitempty"`
66+
Password string `xml:"password,attr,omitempty"`
6367
}

cmd/generate.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ func jsonRegionsToXmlRegions(regions JsonRegions) []XmlRegion {
112112
hostNames := parseHostPattern(hostPattern)
113113
for _, hostName := range hostNames {
114114
xmlHosts = append(xmlHosts, XmlHost{
115-
Name: hostName,
116-
Port: host.Port,
117-
Count: host.Count,
115+
Name: hostName,
116+
Port: host.Port,
117+
Count: host.Count,
118+
Username: host.Username,
119+
Password: host.Password,
118120
})
119121
}
120122
}

cmd/generate_test.go

+36-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package cmd
22

33
import (
44
. "github.com/aandryashin/matchers"
5+
"sort"
56
"testing"
67
)
78

89
func TestParseInputFile(t *testing.T) {
910
input, err := parseInputFile("../test-data/input.json")
1011
AssertThat(t, err, Is{nil})
11-
AssertThat(t, len(input.Hosts), EqualTo{1})
12+
AssertThat(t, len(input.Hosts), EqualTo{2})
1213
AssertThat(t, len(input.Quota), EqualTo{1})
1314
}
1415

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

3334
versions := browser.Versions
34-
AssertThat(t, len(versions), EqualTo{2})
35+
AssertThat(t, len(versions), EqualTo{3})
36+
37+
sort.Slice(versions, func(i, j int) bool {
38+
return versions[i].Number < versions[j].Number
39+
})
40+
3541
firstVersion := versions[0]
36-
AssertThat(t, firstVersion.Number == "33.0" || firstVersion.Number == "42.0", Is{true})
42+
AssertThat(t, firstVersion.Number == "33.0", Is{true})
3743
secondVersion := versions[1]
38-
if firstVersion.Number == "42.0" {
39-
AssertThat(t, secondVersion.Number, EqualTo{"33.0"})
40-
} else {
41-
AssertThat(t, secondVersion.Number, EqualTo{"42.0"})
42-
}
44+
AssertThat(t, secondVersion.Number == "42.0", Is{true})
45+
thirdVersion := versions[2]
46+
AssertThat(t, thirdVersion.Number == "43.0", Is{true})
4347

44-
regions := firstVersion.Regions
45-
AssertThat(t, len(regions), EqualTo{2})
46-
firstRegion := regions[0]
48+
firstRegions := firstVersion.Regions
49+
AssertThat(t, len(firstRegions), EqualTo{2})
50+
firstRegion := firstRegions[0]
4751
AssertThat(t, firstRegion.Name == "region-a" || firstRegion.Name == "region-b", Is{true})
4852

49-
secondRegion := regions[1]
53+
secondRegion := firstRegions[1]
5054
if firstRegion.Name == "region-a" {
5155
AssertThat(t, secondRegion.Name, EqualTo{"region-b"})
5256
} else {
5357
AssertThat(t, secondRegion.Name, EqualTo{"region-a"})
5458
}
5559
AssertThat(t, len(firstRegion.Hosts), EqualTo{20})
5660
AssertThat(t, len(secondRegion.Hosts), EqualTo{20})
61+
62+
for i := 0; i < len(firstRegion.Hosts); i++ {
63+
firstHost := firstRegion.Hosts[i]
64+
secondHost := secondRegion.Hosts[i]
65+
66+
AssertThat(t, firstHost.Username == "" && secondHost.Username == "", Is{true})
67+
AssertThat(t, firstHost.Password == "" && secondHost.Password == "", Is{true})
68+
}
69+
70+
secondRegions := thirdVersion.Regions
71+
AssertThat(t, len(secondRegions), EqualTo{1})
72+
region := secondRegions[0]
73+
AssertThat(t, region.Name == "provider-1", Is{true})
74+
75+
AssertThat(t, len(region.Hosts), EqualTo{5})
76+
77+
for _, host := range region.Hosts {
78+
AssertThat(t, host.Username, EqualTo{"user1"})
79+
AssertThat(t, host.Password, EqualTo{"Password1"})
80+
}
5781
}

test-data/input.json

+13-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
"count": 2
1414
}
1515
}
16+
},
17+
"cloud-provider": {
18+
"provider-1" : {
19+
"cloud-provider-[1:5].com": {
20+
"port": 4444,
21+
"count": 1,
22+
"username": "user1",
23+
"password": "Password1"
24+
}
25+
}
1626
}
1727
},
1828

@@ -22,7 +32,8 @@
2232
"defaultVersion": "33.0",
2333
"versions": {
2434
"33.0": "cloud",
25-
"42.0": "cloud"
35+
"42.0": "cloud",
36+
"43.0": "cloud-provider"
2637
}
2738
}
2839
}
@@ -31,4 +42,4 @@
3142
"aliases": {
3243
"test-quota": ["another-quota"]
3344
}
34-
}
45+
}

0 commit comments

Comments
 (0)