blob: 46d319fe4cae1d796d1d49448d1f600e44690165 [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 testexec_test
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"}
env1 := testexec.Environment{
Dimensions: testexec.DimensionSet{DeviceType: "QEMU"},
}
env2 := testexec.Environment{
Dimensions: testexec.DimensionSet{DeviceType: "NUC"},
}
spec1 := testexec.TestSpec{
Test: test1,
Envs: []testexec.Environment{env1},
}
spec2 := testexec.TestSpec{
Test: test1,
Envs: []testexec.Environment{env1},
}
spec3 := testexec.TestSpec{
Test: test2,
Envs: []testexec.Environment{env1, env2},
}
t.Run("Ensure that environments have names", func(t *testing.T) {
// This will in turn ensure that the associated shards too have
// names.
if env1.Name() == "" {
t.Fatalf("Environment\n%+v\n has an empty name", env1)
}
if env2.Name() == "" {
t.Fatalf("Environment\n%+v\n has an empty name", env2)
}
})
t.Run("Ensure env shared", func(t *testing.T) {
shards := testexec.MakeShards([]testexec.TestSpec{spec1, spec2, spec3})
expected := []*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: env1.Name(),
// 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: env1,
},
{
Name: env2.Name(),
Tests: []testexec.Test{test2},
Env: env2,
},
}
if !reflect.DeepEqual(expected, shards) {
t.Fatalf("expected %v, got %v", expected, shards)
}
})
}