mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
Move and fix GCP storage integration test
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
373b07d590
commit
935b2a4490
@ -1,6 +1,6 @@
|
|||||||
//go:build integration
|
//go:build integration
|
||||||
|
|
||||||
package storage
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/edgelesssys/constellation/kms/storage"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
@ -23,15 +24,15 @@ func TestGoogleCloudStorage(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
ctx := context.Background()
|
containerCtx := context.Background()
|
||||||
|
|
||||||
// Set up the Storage Emulator
|
// Set up the Storage Emulator
|
||||||
t.Log("Creating storage emulator...")
|
t.Log("Creating storage emulator...")
|
||||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
emulator, err := setupEmulator(ctx, cli, storageEmulator)
|
emulator, err := setupEmulator(containerCtx, cli, storageEmulator)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
defer func() { _ = cli.ContainerStop(ctx, emulator.ID, nil) }()
|
defer func() { _ = cli.ContainerStop(containerCtx, emulator.ID, nil) }()
|
||||||
|
|
||||||
// Run the actual test
|
// Run the actual test
|
||||||
t.Setenv("STORAGE_EMULATOR_HOST", "localhost:9000")
|
t.Setenv("STORAGE_EMULATOR_HOST", "localhost:9000")
|
||||||
@ -42,31 +43,31 @@ func TestGoogleCloudStorage(t *testing.T) {
|
|||||||
t.Log("Running test...")
|
t.Log("Running test...")
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*50)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*50)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
storage, err := NewGoogleCloudStorage(ctx, projectName, bucketName, nil, option.WithoutAuthentication())
|
store, err := storage.NewGoogleCloudStorage(ctx, projectName, bucketName, nil, option.WithoutAuthentication())
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
testDEK1 := []byte("test DEK")
|
testDEK1 := []byte("test DEK")
|
||||||
testDEK2 := []byte("more test DEK")
|
testDEK2 := []byte("more test DEK")
|
||||||
|
|
||||||
// request unset value
|
// request unset value
|
||||||
_, err = storage.Get(ctx, "test:input")
|
_, err = store.Get(ctx, "test:input")
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
// test Put method
|
// test Put method
|
||||||
assert.NoError(storage.Put(ctx, "volume01", testDEK1))
|
assert.NoError(store.Put(ctx, "volume01", testDEK1))
|
||||||
assert.NoError(storage.Put(ctx, "volume02", testDEK2))
|
assert.NoError(store.Put(ctx, "volume02", testDEK2))
|
||||||
|
|
||||||
// make sure values have been set
|
// make sure values have been set
|
||||||
val, err := storage.Get(ctx, "volume01")
|
val, err := store.Get(ctx, "volume01")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(testDEK1, val)
|
assert.Equal(testDEK1, val)
|
||||||
val, err = storage.Get(ctx, "volume02")
|
val, err = store.Get(ctx, "volume02")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(testDEK2, val)
|
assert.Equal(testDEK2, val)
|
||||||
|
|
||||||
_, err = storage.Get(ctx, "invalid:key")
|
_, err = store.Get(ctx, "invalid:key")
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.ErrorIs(err, ErrDEKUnset)
|
assert.ErrorIs(err, storage.ErrDEKUnset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupEmulator(ctx context.Context, cli *client.Client, imageName string) (container.ContainerCreateCreatedBody, error) {
|
func setupEmulator(ctx context.Context, cli *client.Client, imageName string) (container.ContainerCreateCreatedBody, error) {
|
||||||
@ -92,8 +93,7 @@ func setupEmulator(ctx context.Context, cli *client.Client, imageName string) (c
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return emulator, err
|
return emulator, err
|
||||||
}
|
}
|
||||||
err = cli.ContainerStart(ctx, emulator.ID, types.ContainerStartOptions{})
|
if err := cli.ContainerStart(ctx, emulator.ID, types.ContainerStartOptions{}); err != nil {
|
||||||
if err != nil {
|
|
||||||
return emulator, err
|
return emulator, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user