X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/a5c83e92d7feea2e104b5515043a76c8c4c56c60..f5c601f1801aaa276f8c335fcb51c373edc0b50c:/chatgpt_fake_helper_test.go diff --git a/chatgpt_fake_helper_test.go b/chatgpt_fake_helper_test.go index ddd4c67..0dca6bb 100644 --- a/chatgpt_fake_helper_test.go +++ b/chatgpt_fake_helper_test.go @@ -35,6 +35,27 @@ type ChatGPTFake struct { access []string } +func newChatGPTFake(t *testing.T) *ChatGPTFake { + t.Helper() + + f := &ChatGPTFake{} + mux := http.NewServeMux() + mux.HandleFunc("POST /api/accounts/deviceauth/usercode", f.userCode) + mux.HandleFunc("POST /api/accounts/deviceauth/token", f.deviceToken) + mux.HandleFunc("POST /oauth/token", f.oauthToken) + + f.Server = httptest.NewServer(mux) + t.Cleanup(f.Close) + + return f +} + +func newTestChatGPTAuth(t *testing.T, server *ChatGPTFake) *ChatGPTAuth { + t.Helper() + + return newChatGPTAuth(filepath.Join(t.TempDir(), chatgptTokenFileName), server.URL) +} + // token returns a new access token that expires after ttl, for a token file // that a test writes. func (f *ChatGPTFake) token(ttl time.Duration) string { @@ -166,27 +187,6 @@ func (f *ChatGPTFake) oauthToken(w http.ResponseWriter, r *http.Request) { chatgptWriteJSON(w, answer) } -func newChatGPTFake(t *testing.T) *ChatGPTFake { - t.Helper() - - f := &ChatGPTFake{} - mux := http.NewServeMux() - mux.HandleFunc("POST /api/accounts/deviceauth/usercode", f.userCode) - mux.HandleFunc("POST /api/accounts/deviceauth/token", f.deviceToken) - mux.HandleFunc("POST /oauth/token", f.oauthToken) - - f.Server = httptest.NewServer(mux) - t.Cleanup(f.Close) - - return f -} - -func newTestChatGPTAuth(t *testing.T, server *ChatGPTFake) *ChatGPTAuth { - t.Helper() - - return newChatGPTAuth(filepath.Join(t.TempDir(), chatgptTokenFileName), server.URL) -} - func chatgptWriteTestTokens(t *testing.T, auth *ChatGPTAuth, access, refresh string) { t.Helper()