Skip to content

Commit

Permalink
fix: Add test in GitHub Actions (#43)
Browse files Browse the repository at this point in the history
* fix: Add test in GitHub Actions
* chore: Remove vendor

Signed-off-by: cegao <ce.gao@outlook.com>
  • Loading branch information
gaocegege authored Dec 16, 2021
1 parent 442ccc6 commit 25538b6
Show file tree
Hide file tree
Showing 556 changed files with 62 additions and 330,308 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go Test
on:
- push
- pull_request
jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
GOPATH: ${{ github.workspace }}/go
defaults:
run:
working-directory: ${{ env.GOPATH }}/src/github.com/deb-sig/double-entry-generator
steps:
- name: Check out code
uses: actions/checkout@v2
with:
path: ${{ env.GOPATH }}/src/github.com/deb-sig/double-entry-generator

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17.2

- name: Check Go modules
run: |
go mod tidy && git add go.*
git diff --cached --exit-code || (echo 'Please run "go mod tidy" to sync Go modules' && exit 1);
- name: Verify gofmt
run: |
make check-format && git add pkg
git diff --cached --exit-code || (echo 'Please run "make format" to verify gofmt' && exit 1);
- name: Run Go test
run: make test
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ BIN_DIR := $(GOPATH)/bin
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint

# All targets.
.PHONY: lint test build container push help clean
.PHONY: lint test build container push help clean test-go test-wechat test-alipay format check-format

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
Expand All @@ -67,7 +67,10 @@ clean: ## Clean all the temporary files
@rm -rf ./bin
@rm -rf ./test/output

test: test-alipay test-wechat ## Run all tests
test: test-go test-alipay test-wechat ## Run all tests

test-go: ## Run Golang tests
@go test ./...

test-alipay: ## Run tests for Alipay provider
@$(SHELL) ./test/alipay-test.sh
Expand All @@ -77,3 +80,6 @@ test-wechat: ## Run tests for WeChat provider

format: ## Format code
@gofmt -s -w pkg

check-format: ## Check if the format looks good.
@go fmt ./...
4 changes: 3 additions & 1 deletion pkg/provider/alipay/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ func conevertType(t TxTypeType) ir.TxType {
}
}

// getMetadata get the metadata (e.g. status, method, category and so on.)
// from order.
func getMetadata(o Order) map[string]string {
// FIXME(TripleZ): hard-coded, bad pattern
source := "支付宝"
var status, method, category, txType, orderId, merchantId, paytime string

paytime = o.PayTime.String()
paytime = o.PayTime.Format(localTimeFmt)

if o.DealNo != "" {
orderId = o.DealNo
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/alipay/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (a *Alipay) translateToOrders(array []string) error {
bill.Category = array[7]
bill.DealNo = array[8]
bill.MerchantId = array[9]
bill.PayTime, err = time.Parse(LocalTimeFmt, array[10]+" +0800")
bill.PayTime, err = time.Parse(localTimeFmt, array[10]+" +0800 CST")
if err != nil {
log.Println("parse create time error:", array[10], err)
return err
Expand Down
8 changes: 5 additions & 3 deletions pkg/provider/alipay/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ package alipay

import "time"

const (
// localTimeFmt set time format to utc+8
localTimeFmt = "2006-01-02 15:04:05 -0700 CST"
)

// Statistics is the Statistics of the bill file.
type Statistics struct {
UserID string `json:"user_id,omitempty"`
Expand Down Expand Up @@ -37,9 +42,6 @@ type Order struct {
MethodAccount string `json:"methodAccount,omitempty"`
}

// LocalTimeFmt set time format to utc+8
const LocalTimeFmt = "2006-01-02 15:04:05 -0700"

// TxTypeType is transanction type defined by alipay.
type TxTypeType string

Expand Down
7 changes: 5 additions & 2 deletions pkg/provider/wechat/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ func conevertType(t OrderType) ir.TxType {
}
}

// getMetadata get the metadata (e.g. status, method, category and so on.)
// from order.
func getMetadata(o Order) map[string]string {
// FIXME(TripleZ): hard-coded, bad pattern
source := "微信支付"
var status, method, category, txType, typeOriginal, orderId, merchantId, paytime string
var status, method, category, txType,
typeOriginal, orderId, merchantId, paytime string

paytime = o.PayTime.String()
paytime = o.PayTime.Format(localTimeFmt)

if o.OrderID != "" {
orderId = o.OrderID
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/wechat/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (w *Wechat) translateToOrders(array []string) error {
}
var bill Order
var err error
bill.PayTime, err = time.Parse(LocalTimeFmt, array[0]+" +0800")
bill.PayTime, err = time.Parse(localTimeFmt, array[0]+" +0800 CST")
if err != nil {
return fmt.Errorf("parse create time %s error: %v", array[0], err)
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/provider/wechat/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package wechat

import "time"

const (
// localTimeFmt set time format to utc+8
localTimeFmt = "2006-01-02 15:04:05 -0700 CST"
)

// Statistics is the Statistics of the bill file.
type Statistics struct {
UserID string `json:"user_id,omitempty"`
Expand Down Expand Up @@ -32,9 +37,6 @@ type Order struct {
Commission float64 // 服务费
}

// LocalTimeFmt set time format to utc+8
const LocalTimeFmt = "2006-01-02 15:04:05 -0700"

// OrderType is the type of the order.
type OrderType string

Expand Down
21 changes: 0 additions & 21 deletions vendor/github.com/cpuguy83/go-md2man/LICENSE.md

This file was deleted.

20 changes: 0 additions & 20 deletions vendor/github.com/cpuguy83/go-md2man/md2man/md2man.go

This file was deleted.

Loading

0 comments on commit 25538b6

Please sign in to comment.