Initial code

pull/1/head
Andrey Ivanov 2023-02-22 16:31:45 +03:00 committed by Андрей Иванов
parent 80239a52b4
commit 6234b40557
10 changed files with 221 additions and 0 deletions

14
.drone.yml Normal file
View File

@ -0,0 +1,14 @@
kind: pipeline
type: exec
name: pipeline
steps:
- name: lint
image: golang
commands:
- make lint
- name: test with race and cover
image: golang
commands:
- make test

4
.gitignore vendored
View File

@ -21,3 +21,7 @@
# Go workspace file
go.work
bin
.idea
.vscode

14
Makefile Normal file
View File

@ -0,0 +1,14 @@
VERSION=$(shell date +%Y.%m)
PROJECT_NAME=w3back
.PHONY: lint
lint: ## Линт всего проекта
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.51.1
golangci-lint run --config=./golangci.yml ./...
.PHONY: test
test: ## Юнит тестирование всего проекта
go test -race -count 100 -timeout 30s ./...
help: ## Print this help and exit
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

26
cmd/main.go Normal file
View File

@ -0,0 +1,26 @@
package main
import (
"context"
"flag"
"github.com/tiburon-777/w3back/internal/scenario"
"log"
)
func main() {
// Парсим флаги приложения.
file := flag.String("scenario", "./test/test.yaml", "path to file with test scenario")
ctx := context.Background()
// Читаем и валидируем файл сценария.
sc, err := scenario.New(ctx, *file)
if err != nil {
log.Fatalf("can't understand test scenario: %v ", err)
}
for key, cs := range sc.Cases {
log.Printf("Case#%d - %s", key, cs.Name)
}
}

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module github.com/tiburon-777/w3back
go 1.18
require gopkg.in/yaml.v2 v2.4.0

4
go.sum Normal file
View File

@ -0,0 +1,4 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

102
golangci.yml Normal file
View File

@ -0,0 +1,102 @@
# This file contains all available configuration options
# with their default values.
# options for analysis running
run:
# default concurrency is a available CPU number
#concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 30m
# include test files or not, default is true
tests: false
# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- bin$
- \.git$
- etc$
- protobuf$
- scripts$
- vendor$
- ^benches/
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
- "_easyjson.go"
- ".pb.go"
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
modules-download-mode: mod
# all available settings of specific linters
linters-settings:
errcheck:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
govet:
# report about shadowed variables
check-shadowing: true
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0.3
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 20
dupl:
# tokens count to trigger issue, 150 by default
threshold: 200
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 150
funlen:
statements: 50
lines: 150
linters:
enable-all: true
disable:
- gci
- exhaustivestruct
- exhaustruct
- gochecknoglobals
- whitespace
- wsl
- wrapcheck
- nlreturn
- gofmt
- gofumpt
fast: false
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
# Exclude lll issues for long lines with go:generate
- linters:
- lll
source: "^//go:generate "
- linters:
- golint
text: "receiver name should be a reflection of its identity"
output:
format: tab

View File

@ -0,0 +1,17 @@
package scenario
import "time"
type Object struct {
Params Params `yaml:"params"`
Cases map[int]Case `yaml:"cases"`
}
type Params struct {
Address string `yaml:"address"`
Timeout time.Duration `yaml:"timeout"`
}
type Case struct {
Name string `yaml:"name"`
}

View File

@ -0,0 +1,21 @@
package scenario
import (
"context"
"gopkg.in/yaml.v2"
"os"
)
func New(ctx context.Context, file string) (*Object, error) {
var obj Object
yamlFile, err := os.ReadFile(file)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(yamlFile, &obj)
if err != nil {
return nil, err
}
return &obj, nil
}

14
test/test.yaml Normal file
View File

@ -0,0 +1,14 @@
{
params: {
address: "http://localhost:9090",
timeout: 10s,
},
cases: {
1: {
name: "case1",
},
2: {
name: "case2",
},
},
}