Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwintye/3350e392f74f56af3779abde04fdaf20 to your computer and use it in GitHub Desktop.
Save edwintye/3350e392f74f56af3779abde04fdaf20 to your computer and use it in GitHub Desktop.
Example main with chan args test
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