ceremonyclient/go-libp2p/scripts/test_analysis/main_test.go
Cassandra Heart dbd95bd9e9
v2.1.0 (#439)
* v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete

* 2.1.0 main node rollup
2025-09-30 02:48:15 -05:00

57 lines
1.3 KiB
Go

package main
import (
"os"
"testing"
)
func TestFailsOnConsistentFailure(t *testing.T) {
tmpDir := t.TempDir() + "/"
os.WriteFile(tmpDir+"/main.go", []byte(`package main
func main() {}`), 0644)
// Add a test that fails consistently.
os.WriteFile(tmpDir+"/main_test.go", []byte(`package main
import (
"testing"
)
func TestConsistentFailure(t *testing.T) {
t.Fatal("consistent failure")
}`), 0644)
os.WriteFile(tmpDir+"/go.mod", []byte(`module example.com/test`), 0644)
tstr := tester{Dir: tmpDir}
err := tstr.runTests(nil)
if err == nil {
t.Fatal("Should have failed with a consistent failure")
}
}
func TestPassesOnFlakyFailure(t *testing.T) {
tmpDir := t.TempDir() + "/"
os.WriteFile(tmpDir+"/main.go", []byte(`package main
func main() {
}`), 0644)
// Add a test that fails the first time.
os.WriteFile(tmpDir+"/main_test.go", []byte(`package main
import (
"os"
"testing"
)
func TestFlakyFailure(t *testing.T) {
_, err := os.Stat("foo")
if err != nil {
os.WriteFile("foo", []byte("hello"), 0644)
t.Fatal("flaky failure")
}
}`), 0644)
os.WriteFile(tmpDir+"/go.mod", []byte(`module example.com/test`), 0644)
// Run the test.
tstr := tester{Dir: tmpDir}
err := tstr.runTests(nil)
if err != nil {
t.Fatal("Should have passed with a flaky test")
}
}