543 - update: to use updated config structure

This commit is contained in:
ameersohel45
2025-11-14 13:06:31 +05:30
parent 9f913e6aa9
commit 75880a4458
5 changed files with 106 additions and 54 deletions

View File

@@ -48,39 +48,64 @@ func TestProvider_New(t *testing.T) {
errMsg: "context cannot be nil",
},
{
name: "missing url",
name: "missing type",
ctx: context.Background(),
config: map[string]string{},
config: map[string]string{"location": server.URL},
wantErr: true,
errMsg: "url not configured",
errMsg: "type not configured",
},
{
name: "empty url",
name: "missing location",
ctx: context.Background(),
config: map[string]string{"url": ""},
config: map[string]string{"type": "url"},
wantErr: true,
errMsg: "url not configured",
errMsg: "location not configured",
},
{
name: "empty type",
ctx: context.Background(),
config: map[string]string{"type": "", "location": server.URL},
wantErr: true,
errMsg: "type not configured",
},
{
name: "empty location",
ctx: context.Background(),
config: map[string]string{"type": "url", "location": ""},
wantErr: true,
errMsg: "location not configured",
},
{
name: "valid config with default TTL",
ctx: context.Background(),
config: map[string]string{"url": server.URL},
config: map[string]string{"type": "url", "location": server.URL},
wantErr: false,
},
{
name: "valid config with custom TTL",
ctx: context.Background(),
config: map[string]string{
"url": server.URL,
"type": "url",
"location": server.URL,
"cacheTTL": "7200",
},
wantErr: false,
},
{
name: "valid file type",
ctx: context.Background(),
config: map[string]string{
"type": "file",
"location": "/tmp/spec.yaml",
},
wantErr: true, // file doesn't exist
},
{
name: "invalid TTL falls back to default",
ctx: context.Background(),
config: map[string]string{
"url": server.URL,
"type": "url",
"location": server.URL,
"cacheTTL": "invalid",
},
wantErr: false,
@@ -89,7 +114,8 @@ func TestProvider_New(t *testing.T) {
name: "negative TTL falls back to default",
ctx: context.Background(),
config: map[string]string{
"url": server.URL,
"type": "url",
"location": server.URL,
"cacheTTL": "-100",
},
wantErr: false,
@@ -98,7 +124,8 @@ func TestProvider_New(t *testing.T) {
name: "zero TTL falls back to default",
ctx: context.Background(),
config: map[string]string{
"url": server.URL,
"type": "url",
"location": server.URL,
"cacheTTL": "0",
},
wantErr: false,