Skip to content

Commit

Permalink
Unit Tests (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Feb 6, 2024
1 parent 47a3d49 commit 3fdf895
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 31 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci-golang-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ci-golang-tests
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
jobs:
golang-lint:
if: github.event_name == 'pull_request'
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '>=1.20.0'
- run: go version
- name: Run Unit Tests
run: |
go install github.com/jstemmer/go-junit-report/v2@latest
go test -v 2>&1 ./... | go-junit-report -set-exit-code > report.xml
- name: Generate Test Summary
if: always()
uses: test-summary/action@v2
with:
paths: "report.xml"

80 changes: 49 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,6 @@ docker run --name hmruntime -p 8686:8686 -v ./plugins:/plugins hypermode/runtime

_Note, if you have previously created a container with the same name, then delete it first with `docker rm hmruntime`._

## AWS Setup
Runtime may access AWS Secret manager, so we need to use an AWS Profile.

```
export AWS_PROFILE=hm-runtime
```
Have the `hm-runtime` profile and sso session configured in `~/.aws/config` file.

To work in Sandbox declare the following profile:
```
[profile hm-runtime]
sso_session = hm-runtime
sso_account_id = 436061841671
sso_role_name = Hypermode-EKS-Cluster-Admin
[sso-session hm-runtime]
sso_start_url = https://d-92674fec42.awsapps.com/start#
sso_region = us-west-2
sso_registration_scopes = sso:account:access
```

If you are using VSCode launcher, check `launch.json` and verify the profile `hm-runtime`.

Then run `aws sso login --profile hm-runtime` to login to the profile.
After SSO login you can start the runtime

```
export AWS_PROFILE=hm-runtime; ./hmruntime --plugins <your plugin folder>
```
You can omit the export if the environment variable is already set.

## Building without Docker

If needed, you can compile and run the Hypermode Runtime without using Docker.
Expand Down Expand Up @@ -152,3 +121,52 @@ docker run --name <CONTAINER_NAME> \
--env=DGRAPH_ALPHA_GRAPHQL=lambda-url=http://host.docker.internal:8686/graphql-worker \
dgraph/standalone:latest
```

## AWS Setup
Runtime may access AWS Secret manager, so we need to use an AWS Profile.

```
export AWS_PROFILE=hm-runtime
```
Have the `hm-runtime` profile and sso session configured in `~/.aws/config` file.

To work in Sandbox declare the following profile:
```
[profile hm-runtime]
sso_session = hm-runtime
sso_account_id = 436061841671
sso_role_name = Hypermode-EKS-Cluster-Admin
[sso-session hm-runtime]
sso_start_url = https://d-92674fec42.awsapps.com/start#
sso_region = us-west-2
sso_registration_scopes = sso:account:access
```

If you are using VSCode launcher, check `launch.json` and verify the profile `hm-runtime`.

Then run `aws sso login --profile hm-runtime` to login to the profile.
After SSO login you can start the runtime

```
export AWS_PROFILE=hm-runtime; ./hmruntime --plugins <your plugin folder>
```
You can omit the export if the environment variable is already set.

### Unit Testing

Unit tests are created using Go's [built-in unit test support](https://go.dev/doc/tutorial/add-a-test).

To run all tests in the project:

```sh
go test ./...
```

Or, you can just run tests in specific folders. For example:

```sh
go test ./functions
```

Tests can also be run from VS Code's Testing panel, and are run automatically for pull requests.
34 changes: 34 additions & 0 deletions functions/ashelpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package functions

import (
"bytes"
"testing"
)

// "Hello World" in Japanese
const testString = "こんにちは、世界"

var testUTF16 = []byte{
0x53, 0x30, 0x93, 0x30,
0x6b, 0x30, 0x61, 0x30,
0x6f, 0x30, 0x01, 0x30,
0x16, 0x4e, 0x4c, 0x75,
}

func Test_EncodeUTF16(t *testing.T) {

arr := encodeUTF16(testString)

if !bytes.Equal(arr, testUTF16) {
t.Errorf("expected %x, got %x", testUTF16, arr)
}
}

func Test_DecodeUTF16(t *testing.T) {

str := decodeUTF16(testUTF16)

if str != testString {
t.Errorf("expected %s, got %s", testString, str)
}
}

0 comments on commit 3fdf895

Please sign in to comment.