github.com/vertgenlab/gonomics@v1.0.0/fileio/http_test.go (about)

     1  package fileio
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  var httpTestingLookUp = []struct {
     8  	local    string
     9  	internet string
    10  }{
    11  	{"testdata/humanGenomeAbstract.txt", "https://raw.githubusercontent.com/vertgenlab/gonomics/main/fileio/testdata/humanGenomeAbstract.txt"},
    12  }
    13  
    14  // TestHttpReader will parse a local text file and a file uploaded to an internew server and compare the lines
    15  // an check if they are exact matches.
    16  func TestHttpReader(t *testing.T) {
    17  	for _, test := range httpTestingLookUp {
    18  		// ReadUrl is the function we are testing to see the reader is processing the lines of data correctly
    19  		internetData := EasyOpen(test.internet)
    20  		var httpData []string
    21  		for data, done := EasyNextLine(internetData); !done; data, done = EasyNextLine(internetData) {
    22  			httpData = append(httpData, data)
    23  		}
    24  
    25  		localData := EasyOpen(test.local)
    26  		var index int = 0
    27  		for line, done := EasyNextLine(localData); !done; line, done = EasyNextLine(localData) {
    28  			if line == httpData[index] {
    29  				index++
    30  			} else {
    31  				t.Errorf("Error: fetching data over http did not equal local copy...\n")
    32  			}
    33  		}
    34  	}
    35  }
    36  
    37  func TestCatUrl(t *testing.T) {
    38  	answer := CatUrl("https://raw.githubusercontent.com/vertgenlab/gonomics/main/fileio/testdata/humanGenomeAbstract.txt")
    39  	localFile := EasyOpen("testdata/humanGenomeAbstract.txt")
    40  	var expected string
    41  	for data, done := EasyNextLine(localFile); !done; data, done = EasyNextLine(localFile) {
    42  		expected = expected + data + "\n"
    43  	}
    44  	if answer != expected {
    45  		t.Errorf("problem with CatUrl")
    46  	}
    47  }