Skip to content

Commit

Permalink
Rewrite test so error case is easier to find
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
  • Loading branch information
chaudum committed Jan 20, 2024
1 parent 4638845 commit 8ec43fe
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions integration/multi_tenant_queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,24 @@ func TestMultiTenantQuery(t *testing.T) {
require.NoError(t, cliTenant2.PushLogLine("lineB", cliTenant2.Now.Add(-45*time.Minute), nil, map[string]string{"job": "fake2"}))

// check that tenant1 only have access to log line A.
matchLines(t, cliTenant1, `{job="fake2"}`, []string{})
matchLines(t, cliTenant1, `{job=~"fake.*"}`, []string{"lineA"})
matchLines(t, cliTenant1, `{job="fake1"}`, []string{"lineA"})
require.ElementsMatch(t, query(t, cliTenant1, `{job="fake2"}`), []string{})
require.ElementsMatch(t, query(t, cliTenant1, `{job=~"fake.*"}`), []string{"lineA"})
require.ElementsMatch(t, query(t, cliTenant1, `{job="fake1"}`), []string{"lineA"})

// check that tenant2 only have access to log line B.
matchLines(t, cliTenant2, `{job="fake1"}`, []string{})
matchLines(t, cliTenant2, `{job=~"fake.*"}`, []string{"lineB"})
matchLines(t, cliTenant2, `{job="fake2"}`, []string{"lineB"})
require.ElementsMatch(t, query(t, cliTenant2, `{job="fake1"}`), []string{})
require.ElementsMatch(t, query(t, cliTenant2, `{job=~"fake.*"}`), []string{"lineB"})
require.ElementsMatch(t, query(t, cliTenant2, `{job="fake2"}`), []string{"lineB"})

// check that multitenant has access to all log lines on same query.
matchLines(t, cliMultitenant, `{job=~"fake.*"}`, []string{"lineA", "lineB"})
matchLines(t, cliMultitenant, `{job="fake1"}`, []string{"lineA"})
matchLines(t, cliMultitenant, `{job="fake2"}`, []string{"lineB"})
matchLines(t, cliMultitenant, `{job="fake3"}`, []string{})
require.ElementsMatch(t, query(t, cliMultitenant, `{job=~"fake.*"}`), []string{"lineA", "lineB"})
require.ElementsMatch(t, query(t, cliMultitenant, `{job="fake1"}`), []string{"lineA"})
require.ElementsMatch(t, query(t, cliMultitenant, `{job="fake2"}`), []string{"lineB"})
require.ElementsMatch(t, query(t, cliMultitenant, `{job="fake3"}`), []string{})
}

func matchLines(t *testing.T, client *client.Client, labels string, expectedLines []string) {
func query(t *testing.T, client *client.Client, labels string) []string {
t.Helper()
resp, err := client.RunRangeQuery(context.Background(), labels)
require.NoError(t, err)

Expand All @@ -62,5 +63,5 @@ func matchLines(t *testing.T, client *client.Client, labels string, expectedLine
lines = append(lines, val[1])
}
}
require.ElementsMatch(t, expectedLines, lines)
return lines
}

0 comments on commit 8ec43fe

Please sign in to comment.