1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/sonar/client_test.go
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

53 lines
1.4 KiB
Go

//go:build unit
// +build unit
package sonar
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestCreate(t *testing.T) {
testURL := "https://example.org/api/"
t.Run("", func(t *testing.T) {
// init
requester := Requester{
Host: testURL,
Username: mock.Anything,
}
// test
request, err := requester.create(http.MethodGet, mock.Anything, &IssuesSearchOption{P: "42"})
// assert
assert.NoError(t, err)
assert.Empty(t, request.URL.Opaque)
assert.Equal(t, http.MethodGet, request.Method)
assert.Equal(t, "https", request.URL.Scheme)
assert.Equal(t, "example.org", request.URL.Host)
assert.Equal(t, "/api/"+mock.Anything, request.URL.Path)
assert.Contains(t, request.Header.Get("Authorization"), "Basic ")
})
}
func TestNewAPIClient(t *testing.T) {
tests := []struct {
name string
host string
want string
}{
{name: mock.Anything, want: "https://example.org/api/", host: "https://example.org"},
{name: mock.Anything, want: "https://example.org/api/", host: "https://example.org/"},
{name: mock.Anything, want: "https://example.org/api/", host: "https://example.org/api"},
{name: mock.Anything, want: "https://example.org/api/", host: "https://example.org/api/"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := NewAPIClient(tt.host, mock.Anything, nil)
assert.Equal(t, tt.want, got.Host)
})
}
}