From 4699b1c1f3bfd64495d66ce3f89797ff9e14eb43 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Mon, 17 Jul 2023 18:04:00 +0200 Subject: dashboard: improve tree origin code testing 1) Ensure we upload a separate Build every time (they must have different ID values). 2) Support specifying kernel commits. 3) Split out the loadBug() functionality. It will be needed later. --- dashboard/app/tree_test.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/dashboard/app/tree_test.go b/dashboard/app/tree_test.go index 30637c91b..79f2dfe08 100644 --- a/dashboard/app/tree_test.go +++ b/dashboard/app/tree_test.go @@ -817,17 +817,21 @@ func (ctx *treeTestCtx) doJob(resp *dashapi.JobPollResp, day int) { if found == nil { ctx.ctx.t.Fatalf("unknown job request: %#v", resp) } - build := testBuild(1) - build.KernelRepo = resp.KernelRepo - build.KernelBranch = resp.KernelBranch - build.KernelCommit = strings.Repeat("f", 40)[:40] // Figure out what should the result be. result := treeTestOK + build := testBuild(1) for _, item := range found.results { if day >= item.fromDay { result = item.result + build.KernelCommit = item.commit } } + if build.KernelCommit == "" { + build.KernelCommit = strings.Repeat("f", 40)[:40] + } + build.KernelRepo = resp.KernelRepo + build.KernelBranch = resp.KernelBranch + build.ID = fmt.Sprintf("%s_%s_%s_%d", resp.KernelRepo, resp.KernelBranch, resp.KernelCommit, day) jobDoneReq := &dashapi.JobDoneReq{ ID: resp.ID, Build: *build, @@ -846,6 +850,16 @@ func (ctx *treeTestCtx) doJob(resp *dashapi.JobPollResp, day int) { } func (ctx *treeTestCtx) ensureLabels(labels ...string) { + ctx.ctx.t.Helper() + bug := ctx.loadBug() + var bugLabels []string + for _, item := range bug.Labels { + bugLabels = append(bugLabels, item.String()) + } + assert.ElementsMatch(ctx.ctx.t, labels, bugLabels) +} + +func (ctx *treeTestCtx) loadBug() *Bug { ctx.ctx.t.Helper() if ctx.bug == nil { ctx.ctx.t.Fatalf("no bug has been created so far") @@ -853,14 +867,7 @@ func (ctx *treeTestCtx) ensureLabels(labels ...string) { bug := new(Bug) ctx.ctx.expectOK(db.Get(ctx.ctx.ctx, ctx.bug.key(ctx.ctx.ctx), bug)) ctx.bug = bug - - var bugLabels []string - for _, item := range bug.Labels { - bugLabels = append(bugLabels, item.String()) - } - sort.Strings(bugLabels) - sort.Strings(labels) - ctx.ctx.expectEQ(labels, bugLabels) + return bug } func (ctx *treeTestCtx) bugLink() string { @@ -906,6 +913,7 @@ const ( type treeTestEntryPeriod struct { fromDay int result treeTestResult + commit string } func TestRepoGraph(t *testing.T) { -- cgit mrf-deployment