forked from GoogleCloudPlatform/golang-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custommetric_test.go
62 lines (49 loc) · 1.15 KB
/
custommetric_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"io/ioutil"
"log"
"os"
"testing"
"time"
"golang.org/x/net/context"
"github.com/GoogleCloudPlatform/golang-samples/internal/testutil"
)
func TestMain(m *testing.M) {
// These functions are noisy.
log.SetOutput(ioutil.Discard)
s := m.Run()
log.SetOutput(os.Stderr)
os.Exit(s)
}
func TestCustomMetric(t *testing.T) {
hc := testutil.SystemTest(t)
ctx, _ := context.WithTimeout(context.Background(), time.Second*30)
s, err := createService(ctx)
if err != nil {
t.Fatal(err)
}
if err := createCustomMetric(s, hc.ProjectID, metricType); err != nil {
t.Fatal(err)
}
for {
_, err = getCustomMetric(s, hc.ProjectID, metricType)
if err == nil {
break
}
time.Sleep(2 * time.Second)
}
if err != nil {
t.Fatal(err)
}
time.Sleep(2 * time.Second)
if err := writeTimeSeriesValue(s, hc.ProjectID, metricType); err != nil {
t.Error(err)
}
time.Sleep(2 * time.Second)
if err := readTimeSeriesValue(s, hc.ProjectID, metricType); err != nil {
t.Error(err)
}
}