-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from stephen-soltesz/master
Use StandardSQL by default
- Loading branch information
Showing
3 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package bq_test | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
|
||
"cloud.google.com/go/bigquery" | ||
"github.com/m-lab/prometheus-bigquery-exporter/bq" | ||
) | ||
|
||
// TestLiveQuery uses a real BigQuery client to connect and run actual queries. | ||
// Requires auth credentials. | ||
// Note: disable this test in travis by specifying "go test -short [...]" | ||
func TestLiveQuery(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping live query tests.") | ||
} | ||
ctx := context.Background() | ||
client, err := bigquery.NewClient(ctx, "mlab-sandbox") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
qr := bq.NewQueryRunner(client) | ||
tests := []struct { | ||
name string | ||
query string | ||
metrics []bq.Metric | ||
}{ | ||
{ | ||
name: "Single value", | ||
query: "SELECT 1 as value", | ||
metrics: []bq.Metric{ | ||
bq.NewMetric(nil, nil, 1.0), | ||
}, | ||
}, | ||
{ | ||
name: "Single value with label", | ||
query: "SELECT 'foo' as key, 2 as value", | ||
metrics: []bq.Metric{ | ||
bq.NewMetric([]string{"key"}, []string{"foo"}, 2.0), | ||
}, | ||
}, | ||
{ | ||
name: "Multiple values with labels", | ||
query: `#standardSQL | ||
SELECT key, value | ||
FROM (SELECT "foo" AS key, 1 AS value UNION ALL | ||
SELECT "bar" AS key, 2 AS value);`, | ||
metrics: []bq.Metric{ | ||
bq.NewMetric([]string{"key"}, []string{"foo"}, 1.0), | ||
bq.NewMetric([]string{"key"}, []string{"bar"}, 2.0), | ||
}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Logf("Live query test: %s", test.name) | ||
metrics, err := qr.Query(test.query) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !reflect.DeepEqual(metrics, test.metrics) { | ||
t.Errorf("Metrics do not match:\nwant %#v;\n got %#v", test.metrics, metrics) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters