From cc44fc6d796cffdd166181f4c74f59654efe6212 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Fri, 20 Dec 2024 11:56:39 +0000 Subject: [PATCH] Add test for validateResourceType --- js/modules/k6/browser/common/http_test.go | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/js/modules/k6/browser/common/http_test.go b/js/modules/k6/browser/common/http_test.go index 357a9cd001b..8869a699c14 100644 --- a/js/modules/k6/browser/common/http_test.go +++ b/js/modules/k6/browser/common/http_test.go @@ -1,6 +1,7 @@ package common import ( + "strings" "testing" "time" @@ -125,3 +126,44 @@ func TestResponse(t *testing.T) { assert.Equal(t, "value", got) }) } + +func TestValidateResourceType(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + input string + want string + }{ + {name: ResourceTypeDocument, input: network.ResourceTypeDocument.String(), want: ResourceTypeDocument}, + {name: ResourceTypeStylesheet, input: network.ResourceTypeStylesheet.String(), want: ResourceTypeStylesheet}, + {name: ResourceTypeImage, input: network.ResourceTypeImage.String(), want: ResourceTypeImage}, + {name: ResourceTypeMedia, input: network.ResourceTypeMedia.String(), want: ResourceTypeMedia}, + {name: ResourceTypeFont, input: network.ResourceTypeFont.String(), want: ResourceTypeFont}, + {name: ResourceTypeScript, input: network.ResourceTypeScript.String(), want: ResourceTypeScript}, + {name: ResourceTypeTextTrack, input: network.ResourceTypeTextTrack.String(), want: ResourceTypeTextTrack}, + {name: ResourceTypeXHR, input: network.ResourceTypeXHR.String(), want: ResourceTypeXHR}, + {name: ResourceTypeFetch, input: network.ResourceTypeFetch.String(), want: ResourceTypeFetch}, + {name: ResourceTypePrefetch, input: network.ResourceTypePrefetch.String(), want: ResourceTypePrefetch}, + {name: ResourceTypeEventSource, input: network.ResourceTypeEventSource.String(), want: ResourceTypeEventSource}, + {name: ResourceTypeWebSocket, input: network.ResourceTypeWebSocket.String(), want: ResourceTypeWebSocket}, + {name: ResourceTypeManifest, input: network.ResourceTypeManifest.String(), want: ResourceTypeManifest}, + {name: ResourceTypeSignedExchange, input: network.ResourceTypeSignedExchange.String(), want: ResourceTypeSignedExchange}, + {name: ResourceTypePing, input: network.ResourceTypePing.String(), want: ResourceTypePing}, + {name: ResourceTypeCSPViolationReport, input: network.ResourceTypeCSPViolationReport.String(), want: ResourceTypeCSPViolationReport}, + {name: ResourceTypePreflight, input: network.ResourceTypePreflight.String(), want: ResourceTypePreflight}, + {name: ResourceTypeOther, input: network.ResourceTypeOther.String(), want: ResourceTypeOther}, + {name: "fake", input: "fake", want: ResourceTypeUnknown}, + {name: "amended_existing", input: strings.ToLower(network.ResourceTypeOther.String()), want: ResourceTypeUnknown}, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got := validateResourceType(log.NewNullLogger(), tt.input) + assert.Equal(t, got, tt.want) + }) + } +}