mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-16 17:48:49 +02:00
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
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()
|
|
}
|