Skip to content

Commit

Permalink
Add test for validateResourceType
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Dec 20, 2024
1 parent f4066e7 commit cc44fc6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions js/modules/k6/browser/common/http_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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)
})
}
}

0 comments on commit cc44fc6

Please sign in to comment.