-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_rate_limits_config_test.go
51 lines (40 loc) · 1.32 KB
/
generate_rate_limits_config_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
package genratelimit_test
import (
"bytes"
"os"
"testing"
genratelimit "github.com/SafetyCulture/protoc-gen-ratelimit"
_ "github.com/SafetyCulture/protoc-gen-ratelimit/extensions/s12_protobuf_ratelimit" // imported for side effects
gendoc "github.com/pseudomuto/protoc-gen-doc"
_ "github.com/pseudomuto/protoc-gen-doc/extensions/google_api_http" // imported for side effects
"github.com/pseudomuto/protokit"
"github.com/pseudomuto/protokit/utils"
"gotest.tools/assert"
)
//go:generate buf build -o fixtures/image.bin
func TestGenerateRateLimitsConfig(t *testing.T) {
set, err := utils.LoadDescriptorSet("fixtures", "image.bin")
assert.NilError(t, err)
req := utils.CreateGenRequest(set, "fixtures/tasks.proto")
result := protokit.ParseCodeGenRequest(req)
template := gendoc.NewTemplate(result)
content, err := genratelimit.GenerateRateLimitsConfig(template, genratelimit.Config{
Domain: "my_domain",
Descriptors: []string{"api_class", "bucket"},
DefaultLimits: []genratelimit.Limit{
{
Key: "",
Value: &genratelimit.YamlRateLimit{
Unit: "minute",
RequestsPerUnit: 1,
},
},
},
})
assert.NilError(t, err)
f, err := os.ReadFile("./fixtures/_generated/config.yaml")
assert.NilError(t, err)
var buf bytes.Buffer
buf.Write(f)
assert.Equal(t, buf.String(), string(content))
}