Skip to content

Commit

Permalink
feat: add tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
cchampou committed Nov 4, 2023
1 parent 6a265b0 commit 7d534e8
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Continuous Deployment
push:
branches:
- main
jobs:
build:
name: Build and publish Docker image
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v2
- name: Build and publish
run: ./build.sh
20 changes: 7 additions & 13 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
name: Continuous Deployment
push:
branches:
- main
name: Continuous Integration
on: [pull_request]

jobs:
build:
name: Build and publish Docker image
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v2
- name: Build and publish
run: ./build.sh
- name: Test
run: go test -v ./...
10 changes: 10 additions & 0 deletions utils/date.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package utils

import (
"time"
)

func GetBeginningOfMonth() time.Time {
now := time.Now()
return time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)
}
23 changes: 23 additions & 0 deletions utils/date_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package utils

import "testing"

func TestGetBeginningOfMonth(t *testing.T) {
date := GetBeginningOfMonth()
println(date.String())
if date.Day() != 1 {
t.Fatalf("Expected day to be 1, got %d", date.Day())
}
if date.Hour() != 0 {
t.Fatalf("Expected hour to be 0, got %d", date.Hour())
}
if date.Minute() != 0 {
t.Fatalf("Expected minute to be 0, got %d", date.Minute())
}
if date.Second() != 0 {
t.Fatalf("Expected second to be 0, got %d", date.Second())
}
if date.Nanosecond() != 0 {
t.Fatalf("Expected nanosecond to be 0, got %d", date.Nanosecond())
}
}

0 comments on commit 7d534e8

Please sign in to comment.