From ff7eb64cd09c7a04261a4336ced8397f7d93a0eb Mon Sep 17 00:00:00 2001 From: Durgesh Singh Date: Thu, 16 May 2024 19:05:30 +0530 Subject: [PATCH] Initial Github Workflow with single test --- .github/workflows/ci-build.yml | 80 +++++++++++++++++++++++++++++++++ internal/pkg/utils/hotp_test.go | 33 ++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 .github/workflows/ci-build.yml create mode 100644 internal/pkg/utils/hotp_test.go diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml new file mode 100644 index 0000000..547e756 --- /dev/null +++ b/.github/workflows/ci-build.yml @@ -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 ./... + + + diff --git a/internal/pkg/utils/hotp_test.go b/internal/pkg/utils/hotp_test.go new file mode 100644 index 0000000..5a15bed --- /dev/null +++ b/internal/pkg/utils/hotp_test.go @@ -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) + } +}