pomerium/cache/memberlist_test.go
Caleb Doxsey fae02791f5
cryptutil: move to pkg dir, add token generator (#1029)
* cryptutil: move to pkg dir, add token generator

* add gitignored files

* add tests
2020-06-30 15:55:33 -06:00

47 lines
910 B
Go

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/pkg/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()
}