Created
April 29, 2022 17:38
-
-
Save edwintye/3350e392f74f56af3779abde04fdaf20 to your computer and use it in GitHub Desktop.
Example main with chan args test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"github.com/stretchr/testify/require" | |
"net" | |
"testing" | |
"time" | |
) | |
func TestMainStart(t *testing.T) { | |
err := errors.New("tmp") | |
done := make(chan bool) | |
go func() { err = Main(done) }() | |
select { | |
case <-time.After(2 * time.Second): | |
done <- true | |
time.Sleep(time.Second) | |
case <-done: | |
} | |
require.NoError(t, err) | |
} | |
func TestMainError(t *testing.T) { | |
var err error | |
done := make(chan bool) | |
net.Listen("tcp", ":8080") | |
go func() { err = Main(done) }() | |
select { | |
case <-time.After(2 * time.Second): | |
done <- true | |
time.Sleep(time.Second) | |
case <-done: | |
} | |
require.Error(t, err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment