blob: 37d0cd0acfc0e4b61cc7df269842464169887fb6 [file] [log] [blame]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package main
import (
"math/rand"
"testing"
"github.com/google/go-cmp/cmp"
buildbucketpb "go.chromium.org/luci/buildbucket/proto"
resultpb "go.chromium.org/luci/resultdb/proto/v1"
"google.golang.org/protobuf/testing/protocmp"
)
func TestClusterFailureModes(t *testing.T) {
buildResults := []buildResult{
{
Build: failedBuild(),
FailedTests: []*resultpb.TestResult{
failedTest("foo", "foo failed"),
},
},
{
Build: failedBuild(),
FailedTests: []*resultpb.TestResult{
failedTest("foo", "foo failed"),
},
},
{
Build: failedBuild(),
FailedTests: []*resultpb.TestResult{
failedTest("bar", "bar failed"),
},
},
{
Build: failedBuild(),
FailedTests: []*resultpb.TestResult{
failedTest("quux", "quux failed"),
},
},
}
clusters := clusterFailureModes(buildResults)
want := map[failureSignature][]buildResult{
{
FailedTest: "foo",
FailureReason: "foo failed",
}: buildResults[:2],
}
if diff := cmp.Diff(want, clusters, protocmp.Transform()); diff != "" {
t.Errorf("Got wrong clusters (-want +got):\n%s", diff)
}
}
func failedBuild() *buildbucketpb.Build {
return &buildbucketpb.Build{
Id: rand.Int63(),
Status: buildbucketpb.Status_FAILURE,
}
}
func failedTest(testID, failureReason string) *resultpb.TestResult {
return &resultpb.TestResult{
TestId: testID,
FailureReason: &resultpb.FailureReason{
PrimaryErrorMessage: failureReason,
},
}
}