github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/internal/testing/pre.go (about) 1 // Copyright 2020 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package testing 6 7 import ( 8 "context" 9 "time" 10 ) 11 12 // Precondition represents a precondition that must be satisfied before a test is run. 13 type Precondition interface { 14 // Prepare is called immediately before starting each test that depends on the precondition. 15 // The returned value will be made available to the test via State.PreValue. 16 // To report an error, Prepare can call either s.Error/Errorf or s.Fatal/Fatalf. 17 // If an error is reported, the test will not run, but the Precondition must be left 18 // in a state where future calls to Prepare (and Close) can still succeed. 19 Prepare(ctx context.Context, s *PreState) interface{} 20 21 // Close is called immediately after completing the final test that depends on the precondition. 22 // This method may be called without an earlier call to Prepare in rare cases (e.g. if 23 // RuntimeConfig.PreTestFunc fails); preconditions must be able to handle this. 24 Close(ctx context.Context, s *PreState) 25 26 // String returns a short, underscore-separated name for the precondition. 27 // "chrome_logged_in" and "arc_booted" are examples of good names for preconditions 28 // defined by the "chrome" and "arc" packages, respectively. 29 String() string 30 31 // Timeout returns the amount of time dedicated to prepare and close the precondition. 32 Timeout() time.Duration 33 }