Skip to content

Commit

Permalink
Adding test when we have no output dir
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspoignant committed Oct 12, 2024
1 parent 0989ba1 commit e2fa717
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions exporter/fileexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thomaspoignant/go-feature-flag/exporter"
"github.com/thomaspoignant/go-feature-flag/exporter/fileexporter"
"github.com/thomaspoignant/go-feature-flag/utils/fflog"
Expand Down Expand Up @@ -419,3 +421,32 @@ func TestFile_IsBulk(t *testing.T) {
exporter := fileexporter.Exporter{}
assert.True(t, exporter.IsBulk(), "DeprecatedExporter is a bulk exporter")
}

func TestExportWithoutOutputDir(t *testing.T) {
featureEvents := []exporter.FeatureEvent{{
Kind: "feature", ContextKind: "anonymousUser", UserKey: "ABCD", CreationDate: 1617970547, Key: "random-key",
Variation: "Default", Value: "YO", Default: false, Source: "SERVER",
}}

filePrefix := "test-flag-variation-EXAMPLE-"
e := fileexporter.Exporter{
Format: "json",
Filename: filePrefix + "{{ .Timestamp}}.{{ .Format}}",
}
err := e.Export(context.Background(), nil, featureEvents)
require.NoError(t, err)

// check that a file exist
files, err := os.ReadDir("./")
require.NoError(t, err)

countFileWithPrefix := 0
for _, file := range files {
if strings.HasPrefix(file.Name(), filePrefix) {
countFileWithPrefix++
err := os.Remove(file.Name())
require.NoError(t, err)
}
}
assert.True(t, countFileWithPrefix > 0, "At least one file should have been created")
}

0 comments on commit e2fa717

Please sign in to comment.