mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-10-01 22:42:26 +08:00

* Lint fixes * Use latest go version for go-check Fixes nil pointer issue in staticcheck * Add test_analysis helper script * Use custom go-test-template * Add some tests to the test_analysis script * Always upload test_results db * Attempt to fix test on windows * Better if statement * Try to fix flaky test * Disable caching setup-go on Windows * Better if statement * Tweak * Always upload summary and artifact * Close db * No extra newline
57 lines
1.3 KiB
Go
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")
|
|
}
|
|
}
|