Skip to content

Commit

Permalink
edge: move tests from edge_test to edge package (minio#367)
Browse files Browse the repository at this point in the history
This commit moves the tests added by 485624f
into the `edge` package.

Further, it converts the single tests to table-driven
tests and adds keystore cleanup to keep test runs predictable.

Tests for `List` and `Delete` are omitted because
the cleanup code first lists and then deletes entries.
So, `List` and `Delete` get tested automatically.

Signed-off-by: Andreas Auernhammer <[email protected]>
  • Loading branch information
aead authored May 16, 2023
1 parent 9f2f43c commit 153a84d
Show file tree
Hide file tree
Showing 18 changed files with 814 additions and 673 deletions.
48 changes: 48 additions & 0 deletions edge/aws_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2023 - MinIO, Inc. All rights reserved.
// Use of this source code is governed by the AGPLv3
// license that can be found in the LICENSE file.

package edge_test

import (
"flag"
"os"
"testing"

"github.com/minio/kes/edge"
)

var awsConfigFile = flag.String("aws.config", "", "Path to a KES config file with AWS SecretsManager config")

func TestAWS(t *testing.T) {
if *awsConfigFile == "" {
t.Skip("AWS SecretsManager tests disabled. Use -aws.config=<FILE> to enable them")
}

file, err := os.Open(*awsConfigFile)
if err != nil {
t.Fatal(err)
}
defer file.Close()

config, err := edge.ReadServerConfigYAML(file)
if err != nil {
t.Fatal(err)
}
if _, ok := config.KeyStore.(*edge.AWSSecretsManagerKeyStore); !ok {
t.Fatalf("Invalid Keystore: want %T - got %T", config.KeyStore, &edge.AWSSecretsManagerKeyStore{})
}

ctx, cancel := testingContext(t)
defer cancel()

store, err := config.KeyStore.Connect(ctx)
if err != nil {
t.Fatal(err)
}

t.Run("Create", func(t *testing.T) { testCreate(ctx, store, t) })
t.Run("Set", func(t *testing.T) { testSet(ctx, store, t) })
t.Run("Get", func(t *testing.T) { testGet(ctx, store, t) })
t.Run("Status", func(t *testing.T) { testStatus(ctx, store, t) })
}
47 changes: 47 additions & 0 deletions edge/azure_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2023 - MinIO, Inc. All rights reserved.
// Use of this source code is governed by the AGPLv3
// license that can be found in the LICENSE file.

package edge_test

import (
"flag"
"os"
"testing"

"github.com/minio/kes/edge"
)

var azureConfigFile = flag.String("azure.config", "", "Path to a KES config file with Azure KeyVault config")

func TestAzure(t *testing.T) {
if *azureConfigFile == "" {
t.Skip("Azure KeyVault tests disabled. Use -azure.config=<FILE> to enable them")
}
file, err := os.Open(*azureConfigFile)
if err != nil {
t.Fatal(err)
}
defer file.Close()

config, err := edge.ReadServerConfigYAML(file)
if err != nil {
t.Fatal(err)
}
if _, ok := config.KeyStore.(*edge.AzureKeyVaultKeyStore); !ok {
t.Fatalf("Invalid Keystore: want %T - got %T", config.KeyStore, &edge.AzureKeyVaultKeyStore{})
}

ctx, cancel := testingContext(t)
defer cancel()

store, err := config.KeyStore.Connect(ctx)
if err != nil {
t.Fatal(err)
}

t.Run("Create", func(t *testing.T) { testCreate(ctx, store, t) })
t.Run("Set", func(t *testing.T) { testSet(ctx, store, t) })
t.Run("Get", func(t *testing.T) { testGet(ctx, store, t) })
t.Run("Status", func(t *testing.T) { testStatus(ctx, store, t) })
}
Loading

0 comments on commit 153a84d

Please sign in to comment.