-
Notifications
You must be signed in to change notification settings - Fork 0
/
featuresheet_test.go
59 lines (48 loc) · 1.5 KB
/
featuresheet_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
package flagsheet_test
import (
"context"
"os"
"testing"
"time"
"github.com/stillmatic/flagsheet"
"github.com/stretchr/testify/assert"
"golang.org/x/oauth2/google"
"gopkg.in/Iwark/spreadsheet.v2"
)
func stringPtr(s string) *string {
return &s
}
const testSpreadsheetID = "15_oV5NcvYK7wK3VVD5ol6KVkWHzPLFl22c1QyLYplpU"
func TestSheet(t *testing.T) {
data, err := os.ReadFile("client_secret.json")
assert.NoError(t, err)
conf, err := google.JWTConfigFromJSON(data, spreadsheet.Scope)
assert.NoError(t, err)
client := conf.Client(context.TODO())
service := spreadsheet.NewServiceWithClient(client)
spreadsheet, err := flagsheet.NewFlagSheet(service, testSpreadsheetID, 1*time.Second)
assert.NoError(t, err)
assert.NotNil(t, spreadsheet)
fv, err := spreadsheet.Evaluate("my_key", stringPtr("my_id"))
assert.Nil(t, err)
assert.NotEmpty(t, fv)
assert.Equal(t, "foo", string(fv))
}
func BenchmarkEvaluate(b *testing.B) {
data, err := os.ReadFile("client_secret.json")
assert.NoError(b, err)
conf, err := google.JWTConfigFromJSON(data, spreadsheet.Scope)
assert.NoError(b, err)
client := conf.Client(context.TODO())
service := spreadsheet.NewServiceWithClient(client)
spreadsheet, err := flagsheet.NewFlagSheet(service, testSpreadsheetID, 1*time.Second)
assert.NoError(b, err)
assert.NotNil(b, spreadsheet)
b.ResetTimer()
for i := 0; i < b.N; i++ {
fv, err := spreadsheet.Evaluate("my_key", stringPtr("my_id"))
assert.Nil(b, err)
assert.NotEmpty(b, fv)
assert.Equal(b, "foo", string(fv))
}
}