-
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.
Signed-off-by: Eray Ates <eates23@gmail.com>
- Loading branch information
Showing
8 changed files
with
181 additions
and
33 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,39 @@ | ||
on: [push] | ||
|
||
name: Test | ||
jobs: | ||
sonarcloud: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: get epository name | ||
run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV | ||
- uses: actions/checkout@v2 | ||
with: | ||
# Disabling shallow clone is recommended for improving relevancy of reporting | ||
fetch-depth: 0 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.20' # The Go version to download (if necessary) and use. | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
- name: Run tests | ||
run: | | ||
[[ ! -f ".golangci.yml" ]] && curl -kfsSL -O https://raw.githubusercontent.com/worldline-go/guide/main/lint/.golangci.yml || true | ||
GOPATH="$(dirname ${PWD})" golangci-lint run --out-format checkstyle ./... > golangci-lint-report.out || true | ||
go test -coverprofile=coverage.out -json ./... > test-report.out | ||
- name: SonarCloud Scan | ||
uses: sonarsource/sonarcloud-github-action@master | ||
with: | ||
args: > | ||
-Dsonar.organization=${{ github.repository_owner }} | ||
-Dsonar.projectKey=${{ github.repository_owner }}_${{ env.REPOSITORY_NAME }} | ||
-Dsonar.go.coverage.reportPaths=coverage.out | ||
-Dsonar.go.tests.reportPaths=test-report.out | ||
-Dsonar.go.golangci-lint.reportPaths=golangci-lint-report.out | ||
-Dsonar.sources=. | ||
-Dsonar.exclusions=**/vendor/**,**/*_test.go | ||
-Dsonar.tests=. | ||
-Dsonar.test.inclusions=**/*_test.go | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/coverage.out | ||
/coverage.html | ||
/coverage.html | ||
/.golangci.yml | ||
/golangci-lint-report.out |
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
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
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
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,51 @@ | ||
package hardloop_test | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/robfig/cron/v3" | ||
"github.com/worldline-go/hardloop" | ||
) | ||
|
||
func Example_parser() { | ||
schedule := "0 7 * * *" | ||
|
||
p := hardloop.Parser{ParseFn: cron.ParseStandard} | ||
|
||
s, err := p.Parse2(schedule) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
now := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC) | ||
|
||
fmt.Println("Next 5 times:") | ||
tmpNow := now | ||
for i := 0; i < 5; i++ { | ||
tmpNow = s.Next(tmpNow) | ||
fmt.Println(tmpNow) | ||
} | ||
|
||
tmpNow = now | ||
fmt.Println("Prev 5 times:") | ||
for i := 0; i < 5; i++ { | ||
tmpNow = s.Prev(tmpNow) | ||
fmt.Println(tmpNow) | ||
} | ||
|
||
// Output: | ||
// Next 5 times: | ||
// 2023-01-01 07:00:00 +0000 UTC | ||
// 2023-01-02 07:00:00 +0000 UTC | ||
// 2023-01-03 07:00:00 +0000 UTC | ||
// 2023-01-04 07:00:00 +0000 UTC | ||
// 2023-01-05 07:00:00 +0000 UTC | ||
// Prev 5 times: | ||
// 2022-12-31 07:00:00 +0000 UTC | ||
// 2022-12-30 07:00:00 +0000 UTC | ||
// 2022-12-29 07:00:00 +0000 UTC | ||
// 2022-12-28 07:00:00 +0000 UTC | ||
// 2022-12-27 07:00:00 +0000 UTC | ||
} |
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
Oops, something went wrong.