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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
package api
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/testing/mock_gitlab"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/testing/testhelpers"
)
func TestGetProjectInfo(t *testing.T) {
const (
projectId = "bla/bla"
)
ctx, traceId := testhelpers.CtxWithSpanContext(t)
response := &GetProjectInfoResponse{
ProjectId: 234,
GitalyInfo: &GitalyInfo{
Address: "example.com",
Token: "123123",
Features: map[string]string{
"a": "b",
},
},
GitalyRepository: &GitalyRepository{
StorageName: "234",
RelativePath: "123",
GlRepository: "254634",
GlProjectPath: "64662",
},
DefaultBranch: "main",
}
gitLabClient := mock_gitlab.SetupClient(t, ProjectInfoApiPath, func(w http.ResponseWriter, r *http.Request) {
testhelpers.AssertRequestMethod(t, r, http.MethodGet)
testhelpers.AssertGetJsonRequestIsCorrect(t, r, traceId)
assert.Equal(t, projectId, r.URL.Query().Get(ProjectIdQueryParam))
testhelpers.RespondWithJSON(t, w, response)
})
projInfo, err := GetProjectInfo(ctx, gitLabClient, testhelpers.AgentkToken, projectId)
require.NoError(t, err)
assert.Equal(t, response.ProjectId, projInfo.ProjectId)
AssertGitalyInfo(t, response.GitalyInfo, projInfo.GitalyInfo)
AssertGitalyRepository(t, response.GitalyRepository, projInfo.Repository)
assert.Equal(t, response.DefaultBranch, projInfo.DefaultBranch)
}
|