From 7fcec3ff75dc967e5e4a1095d39a3dce6ccf60eb Mon Sep 17 00:00:00 2001 From: perennial Date: Mon, 23 Sep 2024 22:34:01 +1000 Subject: [PATCH] Add unit tests for user_agent_list --- config/user_agent_list_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 config/user_agent_list_test.go diff --git a/config/user_agent_list_test.go b/config/user_agent_list_test.go new file mode 100644 index 0000000..7391d14 --- /dev/null +++ b/config/user_agent_list_test.go @@ -0,0 +1,30 @@ +package config + +import ( + "testing" +) + +func TestGetRandomUserAgent(t *testing.T) { + // Test that the function returns a non-empty string + ua := GetRandomUserAgent() + if ua == "" { + t.Error("GetRandomUserAgent returned an empty string") + } + + // Test that the returned user agent is in the list + found := false + for _, builtinUA := range BuiltinUserAgentList { + if ua == builtinUA { + found = true + break + } + } + if !found { + t.Error("GetRandomUserAgent returned a user agent not in BuiltinUserAgentList") + } + + // Test that BuiltinUserAgentList is not empty + if len(BuiltinUserAgentList) == 0 { + t.Error("BuiltinUserAgentList is empty") + } +}