Skip to content

Commit

Permalink
Certificates endpoint test (#47)
Browse files Browse the repository at this point in the history
* feat: add certificates endpoint with test

* feat: update config.example with certificates test
  • Loading branch information
troy0820 authored Oct 26, 2021
1 parent 9a92bd9 commit 2497c3c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ tests:
self-terms-review:
rate: "10/s"
duration: 1
certificates:
rate: "2/s"
duration: 1
33 changes: 33 additions & 0 deletions pkg/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package tests

import (
"bytes"
"encoding/json"
"log"
"math/rand"
"net/http"
"time"

"github.com/cloud-bulldozer/ocm-api-load/pkg/helpers"
"github.com/cloud-bulldozer/ocm-api-load/pkg/tests/handlers"
Expand Down Expand Up @@ -90,6 +93,13 @@ var tests = []types.TestOptions{
Method: http.MethodPost,
Handler: handlers.TestStaticEndpoint,
},
{
TestName: "certificates",
Path: "/api/accounts_mgmt/v1/certificates",
Method: http.MethodPost,
Handler: handlers.TestStaticEndpoint,
Body: certificatesBody(),
},
}

func accessReviewBody() []byte {
Expand Down Expand Up @@ -127,3 +137,26 @@ func resourceReviewBody() []byte {
}
return buff.Bytes()
}

func certificatesBody() []byte {
buff := &bytes.Buffer{}
payload := struct {
Type string `json:"type"`
Arch string `json:"arch"`
}{
"sca",
randomCertArch(),
}
pl, err := json.Marshal(payload)
if err != nil {
log.Printf("marshaling `certificates body` request %s", err)
return buff.Bytes()
}
return bytes.NewBuffer(pl).Bytes()
}

func randomCertArch() string {
rand.Seed(time.Now().UnixNano()) //seed to randomize on each run
arch := []string{"x86", "x86_64", "ppc", "ppc64", "ppc64le", "s390", "s390x", "ia64", "aarch64"}
return arch[rand.Intn(len(arch))]
}
22 changes: 22 additions & 0 deletions pkg/tests/tests_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package tests

import (
"encoding/json"
"testing"
)

func TestCertificateBody(t *testing.T) {
buff := certificatesBody()
type payload struct {
Type string `json:"type"`
Arch string `json:"arch"`
}
var pl payload
err := json.Unmarshal(buff, &pl)
if err != nil {
t.Fatalf("error unmarshaling payload %v", pl)
}
if pl.Type == "" && pl.Arch == "" {
t.Fatalf("certificates body did not return payload to be unmarshaled %v", pl)
}
}

0 comments on commit 2497c3c

Please sign in to comment.