blob: 57b6a6ed6ec136a5a84fc22ae957fa1d87565dca [file] [log] [blame]
// Copyright 2018 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 (
"reflect"
"testing"
"fuchsia.googlesource.com/infra/infra/fuchsia/testexec"
)
func TestMakeShards(t *testing.T) {
test1 := testexec.Test{Location: "/path/to/binary"}
test2 := testexec.Test{Location: "/path/to/binary2"}
device1 := testexec.DeviceSpec{Type: "NUC"}
device2 := testexec.DeviceSpec{Type: "QEMU"}
spec1 := testexec.TestSpec{
Test: test1,
Envs: []testexec.Environment{
{
Device: device1,
},
},
}
spec2 := testexec.TestSpec{
Test: test1,
Envs: []testexec.Environment{
{
Device: device1,
},
},
}
spec3 := testexec.TestSpec{
Test: test2,
Envs: []testexec.Environment{
{
Device: device1,
},
{
Device: device2,
},
},
}
t.Run("Ensure prefix applied", func(t *testing.T) {
shards := makeShards([]testexec.TestSpec{spec1}, "prefix")
expect := []*testexec.Shard{
{
Name: "prefix-0000",
Tests: []testexec.Test{test1},
Env: testexec.Environment{
Device: device1,
},
},
}
if !reflect.DeepEqual(expect, shards) {
t.Fatalf("expected %v, got %v", expect, shards)
}
})
t.Run("Ensure env shared", func(t *testing.T) {
shards := makeShards([]testexec.TestSpec{spec1, spec2, spec3}, "")
expect := []*testexec.Shard{
// Ensure that the order of the shards is the order in which their
// corresponding environments appear in the input. This is the simplest
// deterministic order we can produce for the shards.
{
Name: "0000",
// Ensure that we actually specify the test _twice_, that is, don't
// necessarily deduplicate tests for a shared environment.
Tests: []testexec.Test{test1, test1, test2},
Env: testexec.Environment{
Device: device1,
},
},
{
Name: "0001",
Tests: []testexec.Test{test2},
Env: testexec.Environment{
Device: device2,
},
},
}
if !reflect.DeepEqual(expect, shards) {
t.Fatalf("expected %v, got %v", expect, shards)
}
})
}