Skip to content

Commit

Permalink
fix: Failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Abeeujah committed Nov 19, 2024
1 parent dc27400 commit c1b9b23
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 43 deletions.
7 changes: 6 additions & 1 deletion cmd/relayproxy/service/gofeatureflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ func initRetriever(c *config.RetrieverConf) (retriever.Retriever, error) {
case config.RedisRetriever:
return &redisretriever.Retriever{Options: c.RedisOptions, Prefix: c.RedisPrefix}, nil
case config.AzBlobStorageRetriever:
return &azblobretriever.Retriever{Container: c.Container, Object: c.Object, AccountName: c.AccountName, AccountKey: c.AccountKey}, nil
return &azblobretriever.Retriever{
Container: c.Container,
Object: c.Object,
AccountName: c.AccountName,
AccountKey: c.AccountKey,
}, nil
default:
return nil, fmt.Errorf("invalid retriever: kind \"%s\" "+
"is not supported", c.Kind)
Expand Down
4 changes: 2 additions & 2 deletions retriever/azblobstorageretriever/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

err := retriever.Init(context.Background(), nil)
defer func() { _ = r.Shutdown(context.Background()) }()
err := retriever.Init(ctx, nil)
defer func() { _ = r.Shutdown(ctx) }()
if err != nil {
log.Fatalf("Failed to initialize retriever:", err)
}
Expand Down
78 changes: 38 additions & 40 deletions retriever/azblobstorageretriever/retriever_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package azblobretriever_test
import (
"context"
"fmt"
"log/slog"
"os"
"strings"
"testing"
Expand All @@ -15,55 +16,59 @@ import (
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/azurite"
"github.com/thomaspoignant/go-feature-flag/retriever/azblobstorageretriever"
"github.com/thomaspoignant/go-feature-flag/utils/fflog"
)

var containerName = "testcontainer"

func TestAzureBlobStorageRetriever(t *testing.T) {
type fields struct {
container string
accountName string
accountKey string
object string
serviceURL string
}
tests := []struct {
name string
fields fields
want string
wantErr bool
context context.Context
name string
want string
wantErr bool
context context.Context
retriever azblobretriever.Retriever
}{
{
name: "File on Container",
fields: fields{
container: containerName,
accountName: azurite.AccountName,
accountKey: azurite.AccountKey,
object: "flag-config.yaml",
},
name: "File on Container",
want: "./testdata/flag-config.yaml",
wantErr: false,
retriever: azblobretriever.Retriever{
Container: containerName,
AccountName: azurite.AccountName,
AccountKey: azurite.AccountKey,
Object: "flag-config.yaml",
},
},
{
name: "File on Container with Context",
fields: fields{
container: containerName,
accountName: azurite.AccountName,
accountKey: azurite.AccountKey,
object: "flag-config.yaml",
retriever: azblobretriever.Retriever{
Container: containerName,
AccountName: azurite.AccountName,
AccountKey: azurite.AccountKey,
Object: "flag-config.yaml",
},
want: "./testdata/flag-config.yaml",
context: context.Background(),
wantErr: false,
},
{
name: "File not on Container",
fields: fields{
container: containerName,
accountName: azurite.AccountName,
accountKey: azurite.AccountKey,
object: "feature-config.csv",
retriever: azblobretriever.Retriever{
Container: containerName,
AccountName: azurite.AccountName,
AccountKey: azurite.AccountKey,
Object: "feature-config.csv",
},
wantErr: true,
},
{
name: "Should Err on Empty container",
retriever: azblobretriever.Retriever{
AccountName: azurite.AccountName,
AccountKey: azurite.AccountKey,
Object: "feature-config.csv",
},
wantErr: true,
},
Expand All @@ -73,21 +78,14 @@ func TestAzureBlobStorageRetriever(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
container, _ := setupTest(t)
defer tearDown(t, container)
serviceURL := fmt.Sprintf("%s/%s", container.MustServiceURL(context.Background(), azurite.BlobService), azurite.AccountName)
r := &Retriever{
Container: tt.fields.container,
AccountName: tt.fields.accountName,
AccountKey: tt.fields.accountKey,
ServiceURL: serviceURL,
Object: tt.fields.object,
}
err := r.Init(context.Background(), nil)
tt.retriever.ServiceURL = fmt.Sprintf("%s/%s", container.MustServiceURL(context.Background(), azurite.BlobService), azurite.AccountName)
err := tt.retriever.Init(context.Background(), &fflog.FFLogger{LeveledLogger: slog.Default()})
assert.NoError(t, err)
defer func() {
err := r.Shutdown(context.Background())
err := tt.retriever.Shutdown(context.Background())
assert.NoError(t, err)
}()
got, err := r.Retrieve(tt.context)
got, err := tt.retriever.Retrieve(context.Background())
assert.Equal(t, tt.wantErr, err != nil, "Retrieve() error = %v, wantErr %v", err, tt.wantErr)
if err == nil {
want, err := os.ReadFile(tt.want)
Expand Down

0 comments on commit c1b9b23

Please sign in to comment.