mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-06 11:49:14 +02:00
fix:#41 added error if html request isn't 200
This commit is contained in:
63
services/data-manager/service/fetch/htmlDownloader_test.go
Normal file
63
services/data-manager/service/fetch/htmlDownloader_test.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package fetch
|
||||
|
||||
import (
|
||||
"github.com/jarcoal/httpmock"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetHTMLWithClient(t *testing.T) {
|
||||
|
||||
client := &http.Client{}
|
||||
httpmock.ActivateNonDefault(client)
|
||||
|
||||
type args struct {
|
||||
url string
|
||||
statusCode int
|
||||
method string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Test GetHTML with status code 200",
|
||||
args: args{
|
||||
url: "https://stundenplan.htwk-leipzig.de/ss/Berichte/Text-Listen;Studenten-Sets;name;1-1?template=sws_semgrp&weeks=1-65",
|
||||
method: "GET",
|
||||
statusCode: 200,
|
||||
},
|
||||
want: "",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Test GetHTML with status code 404",
|
||||
args: args{
|
||||
url: "https://stundenplan.htwk-leipzig.de/ss/Berichte/Text-Lists;Studenten-Sets;name;1-1?template=sws_semgrp&weeks=1-65",
|
||||
method: "GET",
|
||||
statusCode: 404,
|
||||
},
|
||||
want: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
httpmock.RegisterResponder(tt.args.method, tt.args.url,
|
||||
httpmock.NewStringResponder(tt.args.statusCode, tt.want))
|
||||
got, err := GetHTMLWithClient(tt.args.url, client)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("GetHTML() error = %v, wantNoErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("GetHTML() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
httpmock.DeactivateAndReset()
|
||||
}
|
Reference in New Issue
Block a user