|
|
6102f0e |
diff -Naurp com-2.orig/http_test.go com-2/http_test.go
|
|
|
6102f0e |
--- com-2.orig/http_test.go 2018-10-11 08:02:13.000000000 +1100
|
|
|
6102f0e |
+++ com-2/http_test.go 1970-01-01 10:00:00.000000000 +1000
|
|
|
6102f0e |
@@ -1,111 +0,0 @@
|
|
|
6102f0e |
-// Copyright 2013 com authors
|
|
|
6102f0e |
-//
|
|
|
6102f0e |
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
|
|
6102f0e |
-// not use this file except in compliance with the License. You may obtain
|
|
|
6102f0e |
-// a copy of the License at
|
|
|
6102f0e |
-//
|
|
|
6102f0e |
-// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
6102f0e |
-//
|
|
|
6102f0e |
-// Unless required by applicable law or agreed to in writing, software
|
|
|
6102f0e |
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
6102f0e |
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
6102f0e |
-// License for the specific language governing permissions and limitations
|
|
|
6102f0e |
-// under the License.
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-package com
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-import (
|
|
|
6102f0e |
- "io/ioutil"
|
|
|
6102f0e |
- "net/http"
|
|
|
6102f0e |
- "strings"
|
|
|
6102f0e |
- "testing"
|
|
|
6102f0e |
-)
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-var examplePrefix = `
|
|
|
6102f0e |
-<html>
|
|
|
6102f0e |
-<head>
|
|
|
6102f0e |
- <title>Example Domain</title>
|
|
|
6102f0e |
-`
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-func TestHttpGet(t *testing.T) {
|
|
|
6102f0e |
- // 200.
|
|
|
6102f0e |
- rc, err := HttpGet(&http.Client{}, "http://example.com", nil)
|
|
|
6102f0e |
- if err != nil {
|
|
|
6102f0e |
- t.Fatalf("HttpGet:\n Expect => %v\n Got => %s\n", nil, err)
|
|
|
6102f0e |
- }
|
|
|
6102f0e |
- p, err := ioutil.ReadAll(rc)
|
|
|
6102f0e |
- if err != nil {
|
|
|
6102f0e |
- t.Errorf("HttpGet:\n Expect => %v\n Got => %s\n", nil, err)
|
|
|
6102f0e |
- }
|
|
|
6102f0e |
- s := string(p)
|
|
|
6102f0e |
- if !strings.HasPrefix(s, examplePrefix) {
|
|
|
6102f0e |
- t.Errorf("HttpGet:\n Expect => %s\n Got => %s\n", examplePrefix, s)
|
|
|
6102f0e |
- }
|
|
|
6102f0e |
-}
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-func TestHttpGetBytes(t *testing.T) {
|
|
|
6102f0e |
- p, err := HttpGetBytes(&http.Client{}, "http://example.com", nil)
|
|
|
6102f0e |
- if err != nil {
|
|
|
6102f0e |
- t.Errorf("HttpGetBytes:\n Expect => %v\n Got => %s\n", nil, err)
|
|
|
6102f0e |
- }
|
|
|
6102f0e |
- s := string(p)
|
|
|
6102f0e |
- if !strings.HasPrefix(s, examplePrefix) {
|
|
|
6102f0e |
- t.Errorf("HttpGet:\n Expect => %s\n Got => %s\n", examplePrefix, s)
|
|
|
6102f0e |
- }
|
|
|
6102f0e |
-}
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-func TestHttpGetJSON(t *testing.T) {
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-}
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-type rawFile struct {
|
|
|
6102f0e |
- name string
|
|
|
6102f0e |
- rawURL string
|
|
|
6102f0e |
- data []byte
|
|
|
6102f0e |
-}
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-func (rf *rawFile) Name() string {
|
|
|
6102f0e |
- return rf.name
|
|
|
6102f0e |
-}
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-func (rf *rawFile) RawUrl() string {
|
|
|
6102f0e |
- return rf.rawURL
|
|
|
6102f0e |
-}
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-func (rf *rawFile) Data() []byte {
|
|
|
6102f0e |
- return rf.data
|
|
|
6102f0e |
-}
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-func (rf *rawFile) SetData(p []byte) {
|
|
|
6102f0e |
- rf.data = p
|
|
|
6102f0e |
-}
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-func TestFetchFiles(t *testing.T) {
|
|
|
6102f0e |
- files := []RawFile{
|
|
|
6102f0e |
- &rawFile{rawURL: "http://example.com"},
|
|
|
6102f0e |
- &rawFile{rawURL: "http://example.com"},
|
|
|
6102f0e |
- }
|
|
|
6102f0e |
- err := FetchFiles(&http.Client{}, files, nil)
|
|
|
6102f0e |
- if err != nil {
|
|
|
6102f0e |
- t.Errorf("FetchFiles:\n Expect => %v\n Got => %s\n", nil, err)
|
|
|
6102f0e |
- } else if len(files[0].Data()) != 1270 {
|
|
|
6102f0e |
- t.Errorf("FetchFiles:\n Expect => %d\n Got => %d\n", 1270, len(files[0].Data()))
|
|
|
6102f0e |
- } else if len(files[1].Data()) != 1270 {
|
|
|
6102f0e |
- t.Errorf("FetchFiles:\n Expect => %d\n Got => %d\n", 1270, len(files[1].Data()))
|
|
|
6102f0e |
- }
|
|
|
6102f0e |
-}
|
|
|
6102f0e |
-
|
|
|
6102f0e |
-func TestFetchFilesCurl(t *testing.T) {
|
|
|
6102f0e |
- files := []RawFile{
|
|
|
6102f0e |
- &rawFile{rawURL: "http://example.com"},
|
|
|
6102f0e |
- &rawFile{rawURL: "http://example.com"},
|
|
|
6102f0e |
- }
|
|
|
6102f0e |
- err := FetchFilesCurl(files)
|
|
|
6102f0e |
- if err != nil {
|
|
|
6102f0e |
- t.Errorf("FetchFilesCurl:\n Expect => %v\n Got => %s\n", nil, err)
|
|
|
6102f0e |
- } else if len(files[0].Data()) != 1270 {
|
|
|
6102f0e |
- t.Errorf("FetchFilesCurl:\n Expect => %d\n Got => %d\n", 1270, len(files[0].Data()))
|
|
|
6102f0e |
- } else if len(files[1].Data()) != 1270 {
|
|
|
6102f0e |
- t.Errorf("FetchFilesCurl:\n Expect => %d\n Got => %d\n", 1270, len(files[1].Data()))
|
|
|
6102f0e |
- }
|
|
|
6102f0e |
-}
|