Add TestSystem

This commit is contained in:
Ian Gulliver
2023-06-04 10:43:32 -07:00
parent 0b9c2543e4
commit bce6488620
3 changed files with 61 additions and 27 deletions

View File

@@ -1,32 +1,17 @@
package elect_test
import (
"fmt"
"testing"
"time"
"github.com/dchest/uniuri"
"github.com/gopatchy/elect"
"github.com/gopatchy/proxy"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
)
func TestSimple(t *testing.T) {
func TestOne(t *testing.T) {
t.Parallel()
signingKey := uniuri.New()
ts := NewTestServer(t, signingKey)
ts := NewTestSystem(t, 1)
defer ts.Stop()
p := lo.Must(proxy.NewProxy(t, ts.Addr()))
defer p.Close()
url := fmt.Sprintf("http://%s/", p.Addr())
v := elect.NewVoter(url, signingKey)
defer v.Stop()
require.Eventually(t, ts.Candidate.IsLeader, 15*time.Second, 100*time.Millisecond)
require.Eventually(t, ts.Candidate(0).IsLeader, 15*time.Second, 100*time.Millisecond)
}