mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-05 13:25:19 +02:00
* feat(gcp): add step to send events to GCP (#4896) * add gcp token handling * add initial step * publish events * add test cases * fix test case --------- Co-authored-by: Jordi van Liempt <35920075+jliempt@users.noreply.github.com> * feat(gcp): Generate and validate the GCP OIDC token (#4899) * test setup for generation of jwt token * oidc token generator * push new step files * formatted code * removed toolchain and jose * removed toolchain:go 1.22.2 --------- Co-authored-by: jliempt <> Co-authored-by: D071696 <sachin.baral.ramesh@sap.com> Co-authored-by: d071696 <153099976+d071696@users.noreply.github.com> * feat(events): add pipeline start and end event (#4900) * add gcp token handling * add initial step * publish events * add test cases * fix test case * move files * add possible values * handle start and end event * add sap events * dependencies --------- Co-authored-by: Jordi van Liempt <35920075+jliempt@users.noreply.github.com> * log successful event publish * remove dummy step * prevent step from failing * improve event creation * improve event creation * simplify eventing * remove detailed events * update parameter scope * update go.sum * fix test case * add missing method * refactor OIDC part * add oidc.go to vault pkg * mock OIDC token retrieval * mock GCP functions * update OIDC function name in Vault mocks * get event data from CPE * don't encode data payload in b64 * remove vault related changes * remove vault changes from step code * remove commented out code * documentation/steps/gcpPublishEvent.md * documentation/steps/gcpPublishEvent.md * remove hardcoded eventData * update roleID * go generate * add ordering key for pubsub event --------- Co-authored-by: Jordi van Liempt <35920075+jliempt@users.noreply.github.com> Co-authored-by: D071696 <sachin.baral.ramesh@sap.com> Co-authored-by: d071696 <153099976+d071696@users.noreply.github.com> Co-authored-by: jliempt <>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package gcp
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/jarcoal/httpmock"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
func TestPublish(t *testing.T) {
|
|
t.Run("success", func(t *testing.T) {
|
|
// init
|
|
projectNumber := "PROJECT_NUMBER"
|
|
topic := "TOPIC"
|
|
token := "TOKEN"
|
|
data := []byte(mock.Anything)
|
|
|
|
apiurl := fmt.Sprintf(api_url, projectNumber, topic)
|
|
|
|
mockResponse := map[string]interface{}{
|
|
"messageIds": []string{"10721501285371497"},
|
|
}
|
|
|
|
// mock
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
httpmock.RegisterResponder(http.MethodPost, apiurl,
|
|
func(req *http.Request) (*http.Response, error) {
|
|
assert.Contains(t, req.Header, "Authorization")
|
|
assert.Equal(t, req.Header.Get("Authorization"), "Bearer TOKEN")
|
|
assert.Contains(t, req.Header, "Content-Type")
|
|
assert.Equal(t, req.Header.Get("Content-Type"), "application/json")
|
|
return httpmock.NewJsonResponse(http.StatusOK, mockResponse)
|
|
},
|
|
)
|
|
|
|
// test
|
|
err := Publish(projectNumber, topic, token, mock.Anything, data)
|
|
// asserts
|
|
assert.NoError(t, err)
|
|
})
|
|
}
|