MCPcopy Index your code
hub / github.com/bytebase/bytebase / TestCheckDatabaseGroupMatch

Function TestCheckDatabaseGroupMatch

backend/utils/utils_test.go:14–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestCheckDatabaseGroupMatch(t *testing.T) {
15 tests := []struct {
16 expression string
17 database *store.DatabaseMessage
18 match bool
19 }{
20 {
21 expression: `resource.database_labels.unit == "gcp"`,
22 database: &store.DatabaseMessage{
23 Metadata: &storepb.DatabaseMetadata{
24 Labels: map[string]string{
25 "unit": "gcp",
26 },
27 },
28 },
29 match: true,
30 },
31 {
32 expression: `resource.database_labels.unit == "aws"`,
33 database: &store.DatabaseMessage{
34 Metadata: &storepb.DatabaseMetadata{
35 Labels: map[string]string{
36 "unit": "gcp",
37 },
38 },
39 },
40 match: false,
41 },
42 {
43 expression: `has(resource.database_labels.unit) && resource.database_labels.unit == "aws"`,
44 database: &store.DatabaseMessage{
45 Metadata: &storepb.DatabaseMetadata{},
46 },
47 match: false,
48 },
49 }
50
51 ctx := context.Background()
52 for _, test := range tests {
53 match, err := CheckDatabaseGroupMatch(ctx, test.expression, test.database)
54 assert.NoError(t, err)
55 assert.Equal(t, test.match, match)
56 }
57}

Callers

nothing calls this directly

Calls 2

CheckDatabaseGroupMatchFunction · 0.85
EqualMethod · 0.65

Tested by

no test coverage detected