(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func TestService_getMatchingMapping(t *testing.T) { |
| 54 | topic0 := config.RegexpOrLiteral{} |
| 55 | topic0.UnmarshalText([]byte(`normal-exact-match`)) |
| 56 | assert.Nil(t, topic0.Regexp) |
| 57 | |
| 58 | topic1 := config.RegexpOrLiteral{} |
| 59 | topic1.UnmarshalText([]byte(`/some-topic-prefix-.*/`)) |
| 60 | assert.NotNil(t, topic1.Regexp) |
| 61 | |
| 62 | logger := loggerpkg.NewSlogLogger( |
| 63 | loggerpkg.WithFormat(loggerpkg.FormatText), |
| 64 | loggerpkg.WithLevel(slog.LevelDebug), |
| 65 | ) |
| 66 | svc, err := NewService(config.Proto{ |
| 67 | Mappings: []config.ProtoTopicMapping{ |
| 68 | { |
| 69 | TopicName: topic0, |
| 70 | KeyProtoType: "foo", |
| 71 | }, |
| 72 | { |
| 73 | TopicName: topic1, |
| 74 | KeyProtoType: "bar", |
| 75 | }, |
| 76 | }, |
| 77 | }, logger) |
| 78 | |
| 79 | assert.NoError(t, err) |
| 80 | require.NotNil(t, svc) |
| 81 | |
| 82 | tests := []struct { |
| 83 | name string |
| 84 | arg string |
| 85 | testFn func(*testing.T) |
| 86 | }{ |
| 87 | { |
| 88 | name: "get a strict mapping", |
| 89 | testFn: func(t *testing.T) { |
| 90 | r, err := svc.getMatchingMapping("normal-exact-match") |
| 91 | assert.NoError(t, err) |
| 92 | require.NotNil(t, r) |
| 93 | assert.Equal(t, "foo", r.KeyProtoType) |
| 94 | assert.Nil(t, r.TopicName.Regexp) |
| 95 | assert.Equal(t, "normal-exact-match", r.TopicName.String()) |
| 96 | assert.Len(t, svc.mappingsByTopic, 2) |
| 97 | }, |
| 98 | }, |
| 99 | { |
| 100 | name: "no match", |
| 101 | testFn: func(t *testing.T) { |
| 102 | r, err := svc.getMatchingMapping("no-match") |
| 103 | assert.Error(t, err) |
| 104 | assert.Equal(t, "no prototype found for the given topic 'no-match'. Check your configured protobuf mappings", err.Error()) |
| 105 | require.Nil(t, r.TopicName.Regexp) |
| 106 | assert.Equal(t, "", r.TopicName.String()) |
| 107 | assert.Len(t, svc.mappingsByTopic, 2) |
| 108 | }, |
| 109 | }, |
| 110 | { |
nothing calls this directly
no test coverage detected
searching dependent graphs…