blob: 91d636b29d5067fa5f7060a4207071cfe9c48260 [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
import (
"testing"
)
func TestTestDevicePlatformsValidation(t *testing.T) {
t.Run("Ensure names are unique", func(t *testing.T) {
platforms := TestDevicePlatforms{
{
Name: "NUC",
Arch: "arm64",
},
{
Name: "NUC",
Arch: "x64",
},
}
if err := platforms.Validate(); err == nil {
t.Fatal("platforms erroneously passed validation")
}
})
}
func TestTestSpecValidation(t *testing.T) {
noPlatforms := TestDevicePlatforms{}
nucPlatform := TestDevicePlatforms{
{
Name: "NUC",
Arch: "x64",
},
}
allArchPlatform := TestDevicePlatforms{
{
Name: "QEMU",
Arch: "*",
},
}
allPlatforms := TestDevicePlatforms{
{
Name: "NUC",
Arch: "x64",
},
{
Name: "QEMU",
Arch: "*",
},
}
t.Run("Ensure error on missing specifier", func(t *testing.T) {
spec := TestSpec{Test: Test{}}
if err := spec.Validate("x64", noPlatforms); err == nil {
t.Fatal("spec erroneously passed validation")
}
})
t.Run("Ensure error on unknown platform", func(t *testing.T) {
spec := TestSpec{
Test: Test{Location: "/path/to/binary"},
Envs: []Environment{
{
Device: DeviceSpec{
Type: "idk friend",
},
},
},
}
if err := spec.Validate("x64", nucPlatform); err == nil {
t.Fatal("spec erroneously passed validation")
}
})
t.Run("Ensure error on unknown arch for platform", func(t *testing.T) {
spec := TestSpec{
Test: Test{Location: "/path/to/binary"},
Envs: []Environment{
{
Device: DeviceSpec{
Type: "NUC",
},
},
},
}
if err := spec.Validate("arm64", nucPlatform); err == nil {
t.Fatal("spec erroneously passed validation")
}
})
t.Run("All arch OK", func(t *testing.T) {
spec := TestSpec{
Test: Test{Location: "/path/to/binary"},
Envs: []Environment{
{
Device: DeviceSpec{
Type: "QEMU",
},
},
},
}
if err := spec.Validate("mycpuarch", allArchPlatform); err != nil {
t.Fatal("good config failed validation:", err)
}
})
t.Run("Basic config OK", func(t *testing.T) {
spec := TestSpec{
Test: Test{Location: "/path/to/binary"},
Envs: []Environment{
{
Device: DeviceSpec{
Type: "NUC",
},
},
},
}
if err := spec.Validate("x64", nucPlatform); err != nil {
t.Fatal("good config failed validation:", err)
}
})
t.Run("Multiple envs OK", func(t *testing.T) {
spec := TestSpec{
Test: Test{Location: "/path/to/binary"},
Envs: []Environment{
{
Device: DeviceSpec{
Type: "NUC",
},
},
{
Device: DeviceSpec{
Type: "QEMU",
},
},
},
}
if err := spec.Validate("x64", allPlatforms); err != nil {
t.Fatal("good config failed validation:", err)
}
})
}