Skip to content

Commit

Permalink
backend: allow internal topics in e2e topic tests (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
weeco authored Aug 23, 2023
1 parent 4c2149d commit 01d93e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 7 additions & 0 deletions backend/pkg/api/api_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ type assertHooks struct {
}

func (a *assertHooks) isCallAllowed(topicName string) bool {
// The target system may have created internal topics, which
// use an underscore prefix by convention. The calls to such topics
// are expected and therefore are allowed.
if strings.HasPrefix(topicName, "_") {
return true
}
pc, _, _, _ := runtime.Caller(1)
fnName := runtime.FuncForPC(pc).Name()
parts := strings.Split(fnName, ".")
Expand Down Expand Up @@ -212,6 +218,7 @@ func (a *assertHooks) getCallReturnValue(topicName string) assertCallReturnValue

func newAssertHooks(t *testing.T, returnValues map[string]map[string]assertCallReturnValue) *Hooks {
h := &assertHooks{
t: t,
allowedCalls: map[string]map[string]bool{},
returnValues: map[string]map[string]assertCallReturnValue{},
}
Expand Down
18 changes: 12 additions & 6 deletions backend/pkg/api/handle_topics_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ func (s *APIIntegrationTestSuite) TestHandleGetTopics() {
err := json.Unmarshal(body, &getRes)
require.NoError(err)

require.Len(getRes.Topics, 3)
assert.Equal(testutil.TopicNameForTest("get_topics_0"), getRes.Topics[0].TopicName)
assert.Equal(testutil.TopicNameForTest("get_topics_1"), getRes.Topics[1].TopicName)
assert.Equal(testutil.TopicNameForTest("get_topics_2"), getRes.Topics[2].TopicName)
// There may be internal topics, thus we need to check GTE
require.GreaterOrEqual(len(getRes.Topics), 3)
topicNames := make([]string, len(getRes.Topics))
for i, topicDetails := range getRes.Topics {
topicNames[i] = topicDetails.TopicName
}

assert.Contains(topicNames, testutil.TopicNameForTest("get_topics_0"))
assert.Contains(topicNames, testutil.TopicNameForTest("get_topics_1"))
assert.Contains(topicNames, testutil.TopicNameForTest("get_topics_2"))
})

t.Run("no see permission", func(t *testing.T) {
Expand Down Expand Up @@ -108,12 +114,12 @@ func (s *APIIntegrationTestSuite) TestHandleGetTopics() {
}
}()

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 1000*time.Second)
defer cancel()

res, body := s.apiRequest(ctx, http.MethodGet, "/api/topics", nil)

assert.Equal(200, res.StatusCode)
require.Equal(200, res.StatusCode)

type response struct {
Topics []*console.TopicSummary `json:"topics"`
Expand Down

0 comments on commit 01d93e9

Please sign in to comment.