mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 02:09:15 +02:00
cache: add test for runMemberList (#1007)
This commit is contained in:
parent
53588396ad
commit
ecdf7ee1a9
1 changed files with 47 additions and 0 deletions
47
cache/memberlist_test.go
vendored
Normal file
47
cache/memberlist_test.go
vendored
Normal 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()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue