storage/kubernetes: run transactional conformance tests
This commit is contained in:
parent
5720ecf412
commit
4ab78d0ded
@ -75,10 +75,13 @@ func (c *Config) open() (*client, error) {
|
|||||||
return nil, fmt.Errorf("create client: %v", err)
|
return nil, fmt.Errorf("create client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't try to synchronize this because creating third party resources is not
|
|
||||||
// a synchronous event. Even after the API server returns a 200, it can still
|
|
||||||
// take several seconds for them to actually appear.
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
// Try to synchronously create the third party resources once. This doesn't mean
|
||||||
|
// they'll immediately be available, but ensures that the client will actually try
|
||||||
|
// once.
|
||||||
|
if err := cli.createThirdPartyResources(); err != nil {
|
||||||
|
log.Printf("failed creating third party resources: %v", err)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
if err := cli.createThirdPartyResources(); err != nil {
|
if err := cli.createThirdPartyResources(); err != nil {
|
||||||
@ -94,12 +97,20 @@ func (c *Config) open() (*client, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
// If the client is closed, stop trying to create third party resources.
|
// If the client is closed, stop trying to create third party resources.
|
||||||
cli.cancel = cancel
|
cli.cancel = cancel
|
||||||
return cli, nil
|
return cli, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createThirdPartyResources attempts to create the third party resources dex
|
||||||
|
// requires or identifies that they're already enabled.
|
||||||
|
//
|
||||||
|
// Creating a third party resource does not mean that they'll be immediately available.
|
||||||
|
//
|
||||||
|
// TODO(ericchiang): Provide an option to wait for the third party resources
|
||||||
|
// to actually be available.
|
||||||
func (cli *client) createThirdPartyResources() error {
|
func (cli *client) createThirdPartyResources() error {
|
||||||
for _, r := range thirdPartyResources {
|
for _, r := range thirdPartyResources {
|
||||||
err := cli.postResource("extensions/v1beta1", "", "thirdpartyresources", r)
|
err := cli.postResource("extensions/v1beta1", "", "thirdpartyresources", r)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package kubernetes
|
package kubernetes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ func TestURLFor(t *testing.T) {
|
|||||||
|
|
||||||
func TestStorage(t *testing.T) {
|
func TestStorage(t *testing.T) {
|
||||||
client := loadClient(t)
|
client := loadClient(t)
|
||||||
conformance.RunTests(t, func() storage.Storage {
|
newStorage := func() storage.Storage {
|
||||||
for _, resource := range []string{
|
for _, resource := range []string{
|
||||||
resourceAuthCode,
|
resourceAuthCode,
|
||||||
resourceAuthRequest,
|
resourceAuthRequest,
|
||||||
@ -88,9 +89,14 @@ func TestStorage(t *testing.T) {
|
|||||||
resourcePassword,
|
resourcePassword,
|
||||||
} {
|
} {
|
||||||
if err := client.deleteAll(resource); err != nil {
|
if err := client.deleteAll(resource); err != nil {
|
||||||
|
// Fatalf sometimes doesn't print the error message.
|
||||||
|
fmt.Fprintf(os.Stderr, "delete all %q failed: %v\n", resource, err)
|
||||||
t.Fatalf("delete all %q failed: %v", resource, err)
|
t.Fatalf("delete all %q failed: %v", resource, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return client
|
return client
|
||||||
})
|
}
|
||||||
|
|
||||||
|
conformance.RunTests(t, newStorage)
|
||||||
|
conformance.RunTransactionTests(t, newStorage)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user