Skip to content

Commit

Permalink
Initial Github Workflow with single test
Browse files Browse the repository at this point in the history
  • Loading branch information
singhdurgesh committed May 16, 2024
1 parent 70057a1 commit ff7eb64
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/ci-build.yml
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 ./...



33 changes: 33 additions & 0 deletions internal/pkg/utils/hotp_test.go
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)
}
}

0 comments on commit ff7eb64

Please sign in to comment.