From 7d534e86b9a8e75d6c1c526db2aee95f95806df4 Mon Sep 17 00:00:00 2001 From: cchampou Date: Sat, 4 Nov 2023 09:00:24 +0100 Subject: [PATCH] feat: add tests in CI --- .github/workflows/CD.yml | 17 +++++++++++++++++ .github/workflows/CI.yml | 20 +++++++------------- utils/date.go | 10 ++++++++++ utils/date_test.go | 23 +++++++++++++++++++++++ 4 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/CD.yml create mode 100644 utils/date.go create mode 100644 utils/date_test.go diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml new file mode 100644 index 0000000..f6ddfdf --- /dev/null +++ b/.github/workflows/CD.yml @@ -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 diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f6ddfdf..288259b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 ./... diff --git a/utils/date.go b/utils/date.go new file mode 100644 index 0000000..53a77b4 --- /dev/null +++ b/utils/date.go @@ -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) +} diff --git a/utils/date_test.go b/utils/date_test.go new file mode 100644 index 0000000..4c2d102 --- /dev/null +++ b/utils/date_test.go @@ -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()) + } +}