cache: add test for runMemberList (#1007)

This commit is contained in:
Cuong Manh Le 2020-06-26 23:54:14 +07:00 committed by GitHub
parent 53588396ad
commit ecdf7ee1a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

47
cache/memberlist_test.go vendored Normal file
View file

@ -0,0 +1,47 @@
package cache
import (
"context"
"net/url"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/pomerium/pomerium/config"
"github.com/pomerium/pomerium/internal/cryptutil"
)
func TestCache_runMemberList(t *testing.T) {
c, err := New(config.Options{
SharedKey: cryptutil.NewBase64Key(),
DataBrokerURL: &url.URL{Scheme: "http", Host: "member1"},
Provider: "google",
})
require.NoError(t, err)
ctx, cancelFunc := context.WithTimeout(context.Background(), 1*time.Second)
defer cancelFunc()
ch := make(chan error)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
ch <- c.runMemberList(ctx)
close(ch)
}()
select {
case <-ctx.Done():
// No error
case err := <-ch:
assert.NoError(t, err)
}
// When we're here, either there an error, or ch was closed already.
assert.NoError(t, <-ch)
wg.Wait()
}