Skip to content

Commit

Permalink
Fix tests and add new ini files
Browse files Browse the repository at this point in the history
  • Loading branch information
Syerram committed Oct 28, 2015
1 parent 4cfe72b commit 55db2ee
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
3 changes: 3 additions & 0 deletions tw_data_test.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Data]
#We can create N data set and the code can recycle through each
Raw=[{"name":"Body", "value":"4566"},{"name":"From", "value": "199999999992"}]
2 changes: 1 addition & 1 deletion tw_load.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Users=200
Concurrency=5
URI=http://127.0.0.1:5000/sms
[Cost]
Unit=0.0075
Unit=0.0075
55 changes: 32 additions & 23 deletions tw_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,61 @@ func TestLoad(t *testing.T) {
t.Log("Populate config data")
{
//pass a temp file with INI data and verify the config object
config_file := "./test_tw_load.ini"
config_file := "./tw_load_test.ini"
config := Config{}
config.populateConfig(*config_file)
config.populateConfig(config_file)
//validate each option
if config.Token != "TestToken" {
if config.Token != "12345566778" {
t.Fatal("Not the same token as expected")
}
if config.Users != 5 {
t.Fatal("Not the same number of users as expected", config.Users, "5")
if config.Users != 200 {
t.Fatal("Not the same number of users as expected", config.Users, "200")
}
if config.Concurrency != 5 {
t.Fatal("Not the same token as expected", config.Token, "TestToken")
t.Fatal("Not the same token as expected", config.Token, "5")
}
if config.URI != "http://localhost:5000/test" {
t.Fatal("Not the same URL as expected", config.URI, "http://localhost:5000/test")

uri := "http://127.0.0.1:5000/sms"
if config.URI != uri {
t.Fatal("Not the same URL as expected", config.URI, uri)
}
if config.Unit != 1 {
t.Fatal("Not the same unit cost as expected", config.Unit, "1")
if config.Unit != 0.0075 {
t.Fatal("Not the same unit cost as expected", config.Unit, "0.0075")
}
}

t.Log("Load request data from data file") {
data_file := "./test_tw_data.ini"
t.Log("Given the need to test downloading content.")
{
config_file := "./tw_load_test.ini"
config := Config{}
config.populateConfig(config_file)

data_file := "./tw_data_test.ini"
request := Request{}
request.unmarshal(*data_file, config)
request.unmarshal(data_file, config)
//validate each option and signature
if len(request.Params) != 2 {
t.Fatal("Not the same request params as expected", len(request.Params), "2")
}
if request.Hashed != "_hashstring_" {
t.Fatal("Not the same hashed string as expected", len(request.Hashed), "_hashstring_")
hashed := "9/sJicrE1hXxBW3H8W21KkdNo3I=" //if this fails, then recompute the hash with the params
if request.Hashed != hashed {
t.Fatal("Not the same hashed string as expected", len(request.Hashed), hashed)
}
}

t.Log("Post requests") {
config_file := "./test_tw_load.ini"
t.Log("Post requests")
{
config_file := "./tw_load_test.ini"
config := Config{}
config.populateConfig(*config_file)
config.populateConfig(config_file)

data_file := "./test_tw_data.ini"
data_file := "./tw_data_test.ini"
request := Request{}
request.unmarshal(*data_file, config)
request.unmarshal(data_file, config)

resp = request.post(config)
if resp.status != "200 OK" {
t.Fatal("Not the same status response", resp.status, "200 OK")
resp := request.post(config)
if resp.Status != "200 OK" {
t.Fatal("Not the same status response", resp.Status, "200 OK")
}
}
}
8 changes: 8 additions & 0 deletions tw_load_test.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Auth]
Token=12345566778
[Load]
Users=200
Concurrency=5
URI=http://127.0.0.1:5000/sms
[Cost]
Unit=0.0075

0 comments on commit 55db2ee

Please sign in to comment.