// // http_helper_test.go // Copyright (C) 2023 tiglog // // Distributed under terms of the MIT license. // package helper_test import ( "fmt" "net/url" "testing" "git.hexq.cn/tiglog/golib/gtest" "git.hexq.cn/tiglog/golib/helper" ) func TestRequestGet(t *testing.T) { headers := map[string]string{ "Authorization": "Bearer foo", } uri := "http://tapp.cmoodle.com/api/query?aa=11" vals := url.Values{} vals.Set("foo", "bar") vals.Set("hello", "δΈ–η•Œ") res, err := helper.RequestGet(uri, vals, headers) gtest.NoError(t, err) gtest.NotEqual(t, "{}", string(res)) } func TestRequestPost(t *testing.T) { headers := map[string]string{ "Authorization": "Bearer foo", "Content-Type": "application/json", } uri := "http://tapp.cmoodle.com/api/post/data?aa=11" data := map[string]any{} data["foo"] = "bar" data["hello"] = "πŸŒδΈ–η•Œ1" res, err := helper.RequestPost(uri, data, headers) gtest.NoError(t, err) fmt.Println(string(res)) headers = map[string]string{ "Authorization": "Bearer foo", "Content-Type": "application/x-www-form-urlencoded", } uri = "http://tapp.cmoodle.com/api/post/form?aa=11" data = map[string]any{} data["foo"] = "bar" data["hello"] = "πŸŒδΈ–η•Œ2" res2, err := helper.RequestPost(uri, data, headers) gtest.NoError(t, err) fmt.Println(string(res2)) }