Skip to content

Commit

Permalink
add tests for github comments
Browse files Browse the repository at this point in the history
  • Loading branch information
moficodes committed May 17, 2021
1 parent 132770d commit 357e4fb
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ VAULT_ADDR=

REDIS_CERT_BASE64=
REDIS_CONNECTION_URL=

TEST_GITHUB_REPO=
TEST_GITHUB_TOKEN=
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .travis/build-and-push.sh

This file was deleted.

4 changes: 3 additions & 1 deletion config/awx-secret.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ metadata:
name: awx-secret
type: Opaque
data:
apikey: <AWX_API_TOKEN_BASE64>
apikey: <AWX_API_KEY>
baseurl: <AWX_CLUSTER_URL>
grantclusterworkflowid: <GRANT_CLUSTER_WORKFLOWID>
4 changes: 3 additions & 1 deletion config/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
run: admin
spec:
containers:
- image: moficodes/ibmcloud-kubernetes-admin:v0.2.24
- image: moficodes/kubeadmin:v0.2.33
imagePullPolicy: Always
name: kubeadmin
env:
Expand Down Expand Up @@ -88,6 +88,8 @@ spec:
secretKeyRef:
name: ibmcloud-secret
key: jwt_secret
- name: GITHUB_ISSUE_REPO
value: "https://github.ibm.com/jja/cloud-workshop-requests"
resources:
limits:
cpu: 1000m
Expand Down
28 changes: 28 additions & 0 deletions internals/github/comment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package github

import (
"testing"

"github.com/moficodes/ibmcloud-kubernetes-admin/pkg/ibmcloud"
)

func TestCommentString(t *testing.T) {
issue := ibmcloud.GithubIssueComment{
IssueNumber: "",
EventName: "ibmcloudevent",
Password: "password",
AccountID: "1234",
GithubUser: "user",
GithubToken: "",
ClusterRequest: ibmcloud.GithubIssueClusterRequest{
Count: 10,
Type: "kubernetes",
ErrorCount: 0,
Regions: "dal-10,dal-12",
},
}
_, err := getCommentString(issue, "../../templates/message.gotmpl")
if err != nil {
t.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion internals/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func processURL(url string) (string, string, string, error) {
}
parts := strings.Split(url, "/")
if len(parts) != 3 {
return "", "", "", fmt.Errorf("malformed url")
return "", "", "", fmt.Errorf("malformed url: " + url)
}
return parts[0], parts[1], parts[2], nil
}
30 changes: 30 additions & 0 deletions internals/github/github_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package github

import (
"os"
"testing"

"github.com/moficodes/ibmcloud-kubernetes-admin/pkg/ibmcloud"
)

func TestCreateComment(t *testing.T) {
issue := ibmcloud.GithubIssueComment{
IssueNumber: os.Getenv("TEST_GITHUB_REPO"),
EventName: "functiontest",
Password: "password",
AccountID: "1234",
GithubUser: "Mofizur-Rahman",
GithubToken: os.Getenv("TEST_GITHUB_TOKEN"),
ClusterRequest: ibmcloud.GithubIssueClusterRequest{
Count: 10,
Type: "kubernetes",
ErrorCount: 0,
Regions: "dal-10,dal-12",
},
}

err := CreateComment(issue, "../../templates/message.gotmpl")
if err != nil {
t.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion internals/server/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func GithubCommentHandler(c echo.Context) error {
return err
}

err := github.CreateComment(*comment, "templates/message.gotmpl")
err := github.CreateComment(*comment, "../../templates/message.gotmpl")

if err != nil {
return err
Expand Down
45 changes: 45 additions & 0 deletions internals/server/github_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package server

import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/labstack/echo/v4"

"github.com/moficodes/ibmcloud-kubernetes-admin/pkg/ibmcloud"
)

func TestGithubCommentHandler(t *testing.T) {
issue := ibmcloud.GithubIssueComment{
IssueNumber: os.Getenv("TEST_GITHUB_REPO"),
EventName: "handlertest",
Password: "password",
AccountID: "1234",
GithubUser: "Mofizur-Rahman",
GithubToken: os.Getenv("TEST_GITHUB_TOKEN"),
ClusterRequest: ibmcloud.GithubIssueClusterRequest{
Count: 10,
Type: "kubernetes",
ErrorCount: 0,
Regions: "dal-10,dal-12",
},
}
b, err := json.Marshal(issue)
if err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer(b)
r := httptest.NewRequest(http.MethodPost, "/github/comment", buf)
w := httptest.NewRecorder()
e := echo.New()
c := e.NewContext(r, w)

err = GithubCommentHandler(c)
if err != nil {
t.Fatal(err)
}
}

0 comments on commit 357e4fb

Please sign in to comment.