-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgithub_test.go
32 lines (27 loc) · 893 Bytes
/
github_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"context"
"net/http"
"testing"
"github.com/google/go-github/v48/github"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/stretchr/testify/assert"
)
func TestGetWorkflowRunLogsURLForRunID(t *testing.T) {
t.Setenv(envVarRepoOwner, "someowner")
t.Setenv(envVarRepoFullName, "someowner/test-repo")
testURL := "https://example.com/some/test/path/to/logs.zip"
mockedHTTPClient := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.GetReposActionsRunsLogsByOwnerByRepoByRunId,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Location", testURL)
w.WriteHeader(http.StatusFound)
}),
),
)
testClient := github.NewClient(mockedHTTPClient)
url, err := getWorkflowRunLogsURLForRunID(context.Background(), testClient, 123)
assert.NoError(t, err)
assert.Equal(t, url.String(), testURL)
}