Skip to content

Commit

Permalink
Add tests for newFilePersister
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Feb 12, 2024
1 parent bb9e169 commit 62d1405
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions browser/file_persister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,67 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/grafana/xk6-browser/env"
"github.com/grafana/xk6-browser/storage"
)

func Test_newFilePersister(t *testing.T) {
t.Parallel()

tests := []struct {
name string
envLookup env.LookupFunc
wantType filePersister
wantErr bool
}{
{
name: "local_no_env_var",
envLookup: func(key string) (string, bool) {
return "", false
},
wantType: &storage.LocalFilePersister{},
},
{
name: "local_empty_env_var",
envLookup: func(key string) (string, bool) {
return "", true
},
wantType: &storage.LocalFilePersister{},
},
{
name: "remote",
envLookup: func(key string) (string, bool) {
return "url=https://127.0.0.1/,basePath=/screenshots,header.1=a", true
},
wantType: &storage.RemoteFilePersister{},
},
{
name: "remote_parse_failed",
envLookup: func(key string) (string, bool) {
return "basePath=/screenshots,header.1=a", true
},
wantErr: true,
},
}
for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

gotType, err := newFilePersister(tt.envLookup)
if tt.wantErr {
assert.Error(t, err)
return
}

assert.NoError(t, err)
assert.IsType(t, tt.wantType, gotType)
})
}
}

func Test_parseEnvVar(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 62d1405

Please sign in to comment.