Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamp type support #4

Merged
merged 3 commits into from Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 32 additions & 35 deletions README.md
Expand Up @@ -8,19 +8,19 @@ Currently, *Sangati* only supports connections to PostgreSQL and its variants. S

## Usage

```
```bash
./sangati -c="path/to/configuration/file.json"
```

## Sample configuration file

```
```json
{
"Databases" : [
{
"Host": "host1.db.mydomain.com",
"Port": 5432,
"DbName": "public",
"Port": 5432,
"DbName": "public",
"Index": 1
},
{ "Host": "backup.db.mydomain.com",
Expand All @@ -29,34 +29,34 @@ Currently, *Sangati* only supports connections to PostgreSQL and its variants. S
"Index": 2
}
],
"Tests": [
{
"Name": "Compare output of one query against one value",
"Tests": [
{
"Name": "Compare output of one query against one value",
"Types": ["int"],
"Queries": [
"Queries": [
{
"DbIndex": 1,
"Query": "SELECT COUNT(1) FROM users"
}
],
"Values": ["0"],
"Operator": "gt"
},
{
"Name": "Compare output of one query against multiple values",
"Types": ["int", "string"],
"Values": ["0"],
"Operator": "gt"
},
{
"Name": "Compare output of one query against multiple values",
"Types": ["int", "string"],
"Queries": [
{
"DbIndex": 1,
"Query": "SELECT name, email FROM users WHERE id = 4"
}
],
"Values": ["Farhan Ahmed", "some@email.com"],
"Operator": "eq"
},
{
"Name": "Compare output of one query against output of another",
"Types": ["date", "int"],
"Values": ["Farhan Ahmed", "some@email.com"],
"Operator": "eq"
},
{
"Name": "Compare output of one query against output of another",
"Types": ["date", "int"],
"Queries": [
{
"DbIndex": 1,
Expand All @@ -67,9 +67,9 @@ Currently, *Sangati* only supports connections to PostgreSQL and its variants. S
"Query": "SELECT create_date, COUNT(1) FROM companies GROUP BY 1 ORDER BY 1"
}
],
"Values": []
}
]
"Values": []
}
]
}

```
Expand All @@ -86,8 +86,8 @@ Single query tests compare the output of a query to the static value(s) specifie

The following operators are available to compare the output of the query to the value(s) specified in the configuration file.

```
lt Less than
```csv
lt Less than
lte Less than or equal to
gt Greater than
gte Greater than or equal to
Expand All @@ -104,13 +104,13 @@ Multi-query tests compare the output of one SQL statement to the output of anoth

* How do I specify the databases where the queries must be executed?

```
{
"Host": "myhost.somedomain.com",
"Port": 5432,
"DbName": "main"
```json
{
"Host": "myhost.somedomain.com",
"Port": 5432,
"DbName": "main"
"Index": 1
}
}
```

The username and password must be specified as environment variables `DBUSER1` and `DBPASS1` respectively. If the environment variables are not set, Sangati assumes that the username and password are empty. When specifying multiple databases, the name of the environment variables to be set is the concatenation of `DBUSER` and `DBPASS` with the value of the `Index` field.
Expand All @@ -125,7 +125,4 @@ Currently, Sangati supports three data types --

* What databases do you currently support?

Only PostgreSQL is currently supported. Support for other databases is coming soon.



Only PostgreSQL is currently supported. Support for other databases is coming soon.
2 changes: 1 addition & 1 deletion parser.go
Expand Up @@ -61,7 +61,7 @@ func validateTestStructure(test *Test) error {
return errors.New("The Types array must contain at least one supported type")
}
for _, typ := range test.Types {
if typ != "string" && typ != "int" && typ != "date" {
if typ != "string" && typ != "int" && typ != "date" && typ != "timestamp" {
return errors.New("The Types array contains an unsupported type")
}
}
Expand Down
9 changes: 9 additions & 0 deletions sangati.go
Expand Up @@ -98,6 +98,15 @@ func runSingleQueryTest(test Test, dbConns map[int]*sql.DB) (bool, error) {
if !compareTime(value.(time.Time), expected, test.Operator) {
return false, fmt.Errorf("Logical constraint failed (expected= %v, returned= %v, operator= %v)", expected, value.(time.Time), test.Operator)
}
case "timestamp":
expected, err := time.Parse("2006-02-01 15:04:05.000000", test.Values[i])
if err != nil {
return false, err
}

if !compareTime(value.(time.Time), expected, test.Operator) {
return false, fmt.Errorf("Logical constraint failed (expected= %v, returned=%v, operator=%v)", expected, value.(time.Time), test.Operator)
}
default:
return false, fmt.Errorf("Unexpected type specified (%v)", test.Types[i])
}
Expand Down