(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func 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 | } |
nothing calls this directly
no test coverage detected