blob: 02510c94ed5ce844517c513eb8de4d259964ec7d [file] [log] [blame]
// Copyright 2021 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 codifier
import (
"testing"
)
func TestGNFormat(t *testing.T) {
var p *Proc
if p.GNFormat() != nil {
t.Error("expected nil Proc")
}
p = NewProcFromString("foo")
if p.GNFormat() == nil {
t.Error("expected non-nil Proc")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
}
func TestBuild(t *testing.T) {
var p *Proc
if p.Build() != nil {
t.Error("expected nil Proc")
}
}
func TestRestoreOnFail(t *testing.T) {
var p *Proc
if p.RestoreOnFail() != nil {
t.Error("expected nil Proc")
}
p = NewProcFromString("foo")
if p.RestoreOnFail() == nil {
t.Error("expected non-nil Proc")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
}
func TestCommitOrRestore(t *testing.T) {
var p *Proc
if p.CommitOrRestore("", true) != nil {
t.Error("expected nil Proc")
}
}
func TestCommit(t *testing.T) {
var p *Proc
if p.Commit("", true) != nil {
t.Error("expected nil Proc")
}
p = NewProcFromString("foo")
if p.Commit("", true) == nil {
t.Error("expected non-nil Proc")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
}
func TestBuildSucceeded(t *testing.T) {
var p *Proc
_, err := p.BuildSucceeded()
if err == nil {
t.Error("expected error due to nil Proc")
}
p = NewProcFromString("foo")
s, err := p.BuildSucceeded()
if err != nil {
t.Error("expected no error")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
if s != false {
t.Error("expected build failed")
}
p.buildSuccess = true
s, err = p.BuildSucceeded()
if err != nil {
t.Error("expected nil error")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
if s == false {
t.Error("expected build success")
}
}
func TestTest(t *testing.T) {
var p *Proc
p = p.Test("foo", true)
if p != nil {
t.Error("expected nil Proc")
}
p = NewProcFromString("foo").Test("bar", true)
if p != nil {
t.Error("expected nil Proc")
}
x := newFxTest("fff")
if x == nil {
t.Error("expected non-nil tester")
}
if p != nil {
t.Error("expected nil Proc") // Because test "bar" isn't present in store.
}
}
func TestTestSucceeded(t *testing.T) {
var p *Proc
_, err := p.TestSucceeded()
if err == nil {
t.Error("expected error due to nil Proc")
}
p = NewProcFromString("foo")
s, err := p.TestSucceeded()
if err != nil {
t.Error("expected no error")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
if s != false {
t.Error("expected test failed")
}
p.testSuccess = true
s, err = p.TestSucceeded()
if err != nil {
t.Error("expected nil error")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
if s == false {
t.Error("expected test success")
}
}
func TestSucceeded(t *testing.T) {
var p *Proc
_, err := p.Success()
if err == nil {
t.Error("expected error due to nil Proc")
}
p = NewProcFromString("foo")
s, err := p.Success()
if err != nil {
t.Error("expected no error")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
if s != false {
t.Error("expected test failed")
}
p.buildSuccess = true
s, err = p.Success()
if err != nil {
t.Error("expected nil error")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
if s == true {
t.Error("expected success false")
}
p.testSuccess = true
s, err = p.Success()
if err != nil {
t.Error("expected nil error")
}
if p.replacement != "foo" {
t.Error("expected unchanged replacement")
}
if s == false {
t.Error("expected success true") // Now that both are true.
}
}
func TestAssertNoBootTest(t *testing.T) {
var p *Proc
p = p.AssertNoBootTest("foo")
if p != nil {
t.Error("expected nil Proc")
}
p = NewProcFromString("foo")
if p == nil {
t.Error("expected non-nil Proc")
}
p = p.AssertNoBootTest("foo")
if p != nil {
t.Error("expected nil Proc") // Because test "bar" isn't present in store.
}
}