{"id":13413912,"url":"https://github.com/posener/wstest","last_synced_at":"2025-07-29T10:33:55.274Z","repository":{"id":57483655,"uuid":"86860439","full_name":"posener/wstest","owner":"posener","description":"go websocket client for unit testing of a websocket handler","archived":false,"fork":false,"pushed_at":"2020-12-30T21:32:28.000Z","size":54,"stargazers_count":102,"open_issues_count":1,"forks_count":18,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-29T17:48:32.415Z","etag":null,"topics":["go","golang","gorilla","gorilla-websocket","test","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/posener.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-31T21:06:18.000Z","updated_at":"2025-06-14T23:12:55.000Z","dependencies_parsed_at":"2022-08-28T17:01:58.029Z","dependency_job_id":null,"html_url":"https://github.com/posener/wstest","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/posener/wstest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fwstest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fwstest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fwstest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fwstest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posener","download_url":"https://codeload.github.com/posener/wstest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fwstest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267670434,"owners_count":24125137,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","gorilla","gorilla-websocket","test","websocket"],"created_at":"2024-07-30T20:01:52.593Z","updated_at":"2025-07-29T10:33:55.249Z","avatar_url":"https://github.com/posener.png","language":"Go","funding_links":[],"categories":["Testing","测试相关","测试","Template Engines","Testing Frameworks","测试相关`测试库和测试数据集生成库`","測試","\u003cspan id=\"测试-testing\"\u003e测试 Testing\u003c/span\u003e"],"sub_categories":["Testing Frameworks","HTTP Clients","查询语","HTTP客户端","Advanced Console UIs","高级控制台界面","交流","高級控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"# wstest\n\n[![Build Status](https://travis-ci.org/posener/wstest.svg?branch=master)](https://travis-ci.org/posener/wstest)\n[![codecov](https://codecov.io/gh/posener/wstest/branch/master/graph/badge.svg)](https://codecov.io/gh/posener/wstest)\n[![GoDoc](https://godoc.org/github.com/posener/wstest?status.svg)](http://godoc.org/github.com/posener/wstest)\n[![Go Report Card](https://goreportcard.com/badge/github.com/posener/wstest)](https://goreportcard.com/report/github.com/posener/wstest)\n\nA websocket client for unit-testing a websocket server\n\nThe [gorilla organization](http://www.gorillatoolkit.org/) provides full featured\n[websocket implementation](https://github.com/gorilla/websocket) that the standard library lacks.\n\nThe standard library provides a `httptest.ResponseRecorder` struct that test\nan `http.Handler` without `ListenAndServe`, but is helpless when the connection is being hijacked\nby an http upgrader. As for testing websockets, it has the `httptest.NewServer` that actually\nlistens on a socket on an arbitrary port.\n\nThis package provides a NewDialer function to test just the `http.Handler` that upgrades\nthe connection to a websocket session. It runs the handler function in a goroutine\nwithout listening on any port. The returned `websocket.Dialer` then can be used to dial and communicate\nwith the given handler.\n\n## Get\n\n`go get -u github.com/posener/wstest`\n\n## Examples\n\nSee the [example test](./example_test.go).\n\nAn example how to modify a test function from using\n`httptest.Server` to use `wstest.NewDialer` function.\n\n```diff\nfunc TestHandler(t *testing.T) {\n\tvar err error\n\n\th := \u0026myHandler{}\n-\ts := httptest.NewServer(h)\n-\tdefer s.Close()\n-\td := websocket.Dialer{}\n+\td := wstest.NewDialer(h)\n\n-\tc, resp, err := d.Dial(\"ws://\" + s.Listener.Addr().String() + \"/ws\", nil)\n+\tc, resp, err := d.Dial(\"ws://\" + \"whatever\" + \"/ws\", nil)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\t\n\tif got, want := resp.StatusCode, http.StatusSwitchingProtocols; got != want {\n\t\tt.Errorf(\"resp.StatusCode = %q, want %q\", got, want)\n\t}\n\t\n\terr = c.WriteJSON(\"test\")\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposener%2Fwstest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposener%2Fwstest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposener%2Fwstest/lists"}