-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Github Workflow with single test
- Loading branch information
1 parent
70057a1
commit ff7eb64
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: "CI-TEST-SUITE" | ||
run-name: ${{ github.actor }} is running Test Suites | ||
|
||
on: | ||
# To save cost, we only want to run CI for opened pull request by default | ||
# Some branch like master is an exception | ||
pull_request: | ||
# Only runs if PR on master or main branch | ||
branches: | ||
- "main" | ||
# Reference: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- ready_for_review | ||
|
||
push: | ||
branches: | ||
- 'master' | ||
paths-ignore: | ||
- '.github/**' | ||
- '.dependabot/**' | ||
- 'eol.txt' | ||
- 'docker-compose*' | ||
- 'README.md' | ||
- 'deployments/Dockerfile*' | ||
- '.dockerignore' | ||
workflow_dispatch: | ||
|
||
env: | ||
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | ||
|
||
jobs: | ||
# If we enable DUAL_CI, we will run CI for both Gemfile.lock & Gemfile.next.lock | ||
# Otherwise, just run for Gemfile.lock | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go-version: [1.21] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go ${{ matrix.go-version }} | ||
uses: actions@setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
# Check if the Go has been installed with Correct Version | ||
- name: Display Go version | ||
run: go version | ||
- name: Install dependencies | ||
run: go get . | ||
test: | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
services: | ||
postgres: | ||
image: postgis/postgis:12-3.4-alpine | ||
volumes: | ||
- postgres:/var/lib/postgresql/data | ||
ports: | ||
- "5432:5432" | ||
env: | ||
POSTGRES_PASSWORD: postgres | ||
redis: | ||
image: redis:4.0-alpine | ||
volumes: | ||
- redis:/data | ||
ports: | ||
- "6379:6379" | ||
rabbit_mq: | ||
image: rabbitmq:3-management-alpine | ||
ports: | ||
- 5672:5672 | ||
steps: | ||
- name: Test with Go | ||
run: go test ./... | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/singhdurgesh/rednote/cmd/app" | ||
"github.com/singhdurgesh/rednote/configs" | ||
) | ||
|
||
func TestValidateOTP(t *testing.T) { | ||
app.Config = &configs.Config{Jwt: configs.Jwt{Secret: "Text"}} | ||
|
||
valid := ValidateOTP("", 1) | ||
if valid == true { | ||
t.Errorf("Expected false but got %v", valid) | ||
} | ||
|
||
counter := uint64(1) | ||
otp, _ := GenerateHOTP(counter) | ||
// OTP is passed as blank | ||
fmt.Println(t) | ||
valid = ValidateOTP(otp, counter+1) | ||
|
||
if valid == true { | ||
t.Errorf("Expected false but got %v", valid) | ||
} | ||
|
||
valid = ValidateOTP(otp, counter) | ||
if valid == false { | ||
t.Errorf("Expected true but got %v", valid) | ||
} | ||
} |