diff --git a/browser/file_persister_test.go b/browser/file_persister_test.go index a950843b0..b16421521 100644 --- a/browser/file_persister_test.go +++ b/browser/file_persister_test.go @@ -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()