Skip to content

Commit

Permalink
new version hw
Browse files Browse the repository at this point in the history
  • Loading branch information
DimVlas authored and DimVlas committed Oct 7, 2024
1 parent 1864dd9 commit bc7f5a2
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 75 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ~1.19
go-version: ~1.22

- name: Check out code
uses: actions/checkout@v3

- name: Linters
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: v1.57.2
working-directory: ${{ env.BRANCH }}

tests:
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.19
go-version: ^1.22

- name: Check out code
uses: actions/checkout@v3
Expand All @@ -67,7 +67,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.19
go-version: ^1.22

- name: Check out code
uses: actions/checkout@v3
Expand Down
17 changes: 1 addition & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@ linters-settings:
funlen:
lines: 150
statements: 80
depguard:
rules:
main:
list-mode: lax
files:
- $all
- "!$test"
allow:
- $gostd
test:
files:
- "$test"
allow:
- $gostd
- "github.com/stretchr/testify/require"

issues:
exclude-rules:
Expand All @@ -37,10 +22,10 @@ linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- depguard
- dogsled
- dupl
- bodyclose
- durationcheck
- errorlint
- exhaustive
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
[Инструкция по сдаче ДЗ](https://github.com/OtusGolang/home_work/wiki#%D0%A1%D1%82%D1%83%D0%B4%D0%B5%D0%BD%D1%82%D0%B0%D0%BC).

---
Используемая версия [golangci-lint](https://golangci-lint.run/usage/install/#other-ci): <b>v1.50.1</b>
Используемая версия [golangci-lint](https://golangci-lint.run/usage/install/#other-ci): <b>v1.57.2</b>
```
$ golangci-lint version
golangci-lint has version 1.50.1 built from 8926a95 on 2022-10-22T10:48:48Z
golangci-lint has version 1.57.2 built with go1.22.1 from 77a8601a on 2024-03-28T19:01:11Z
```

---
Expand Down
4 changes: 2 additions & 2 deletions hw01_hello_otus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Hello, OTUS!
```

Для переворота строки следует воспользоваться возможностями
[golang.org/x/example/stringutil](https://pkg.go.dev/golang.org/x/example/stringutil).
[golang.org/x/example/hello/reverse](https://pkg.go.dev/golang.org/x/example/hello/reverse).

Кроме этого необходимо исправить **go.mod** так, чтобы для данного модуля работала
команда `go get`, а полученный **go.sum** закоммитить.

### Критерии оценки
- Пайплайн зелёный - 4 балла
- Используется `stringutil` - 4 балла
- Используется `reverse` - 4 балла
- Понятность и чистота кода - до 2 баллов

#### Зачёт от 7 баллов
Expand Down
2 changes: 1 addition & 1 deletion hw01_hello_otus/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/DimVlas/otus_hw/hw01_hello_otus

go 1.19
go 1.22

require golang.org/x/example v0.0.0-20230731131755-00c7068f9d83
2 changes: 1 addition & 1 deletion hw02_unpack_string/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw02_unpack_string

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
2 changes: 1 addition & 1 deletion hw03_frequency_analysis/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw03_frequency_analysis

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
4 changes: 2 additions & 2 deletions hw04_lru_cache/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/fixme_my_friend/hw04_lru_cache
module github.com/DimVlas/otus_hw/hw04_lru_cache

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
2 changes: 1 addition & 1 deletion hw05_parallel_execution/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw05_parallel_execution

go 1.19
go 1.22

require (
github.com/stretchr/testify v1.7.0
Expand Down
3 changes: 2 additions & 1 deletion hw06_pipeline_execution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func Stage(in <-chan interface{}) (out <-chan interface{}) {
### Критерии оценки
- CI-пайплайн зелёный - 5 баллов
- Добавлены новые юнит-тесты - до 2 баллов
- Понятность и чистота кода - до 3 баллов
- Проходит тест TestAllStageStop - 2 балла
- Понятность и чистота кода - до 1 баллов

#### Зачёт от 7 баллов

Expand Down
2 changes: 1 addition & 1 deletion hw06_pipeline_execution/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw06_pipeline_execution

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
62 changes: 62 additions & 0 deletions hw06_pipeline_execution/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hw06pipelineexecution

import (
"strconv"
"sync"
"testing"
"time"

Expand All @@ -13,6 +14,8 @@ const (
fault = sleepPerStage / 2
)

var isFullTesting = true

func TestPipeline(t *testing.T) {
// Stage generator
g := func(_ string, f func(v interface{}) interface{}) Stage {
Expand Down Expand Up @@ -136,6 +139,65 @@ func TestPipeline(t *testing.T) {
})
}

func TestAllStageStop(t *testing.T) {
if !isFullTesting {
return
}
wg := sync.WaitGroup{}
// Stage generator
g := func(_ string, f func(v interface{}) interface{}) Stage {
return func(in In) Out {
out := make(Bi)
wg.Add(1)
go func() {
defer wg.Done()
defer close(out)
for v := range in {
time.Sleep(sleepPerStage)
out <- f(v)
}
}()
return out
}
}

stages := []Stage{
g("Dummy", func(v interface{}) interface{} { return v }),
g("Multiplier (* 2)", func(v interface{}) interface{} { return v.(int) * 2 }),
g("Adder (+ 100)", func(v interface{}) interface{} { return v.(int) + 100 }),
g("Stringifier", func(v interface{}) interface{} { return strconv.Itoa(v.(int)) }),
}

t.Run("done case", func(t *testing.T) {
in := make(Bi)
done := make(Bi)
data := []int{1, 2, 3, 4, 5}

// Abort after 200ms
abortDur := sleepPerStage * 2
go func() {
<-time.After(abortDur)
close(done)
}()

go func() {
for _, v := range data {
in <- v
}
close(in)
}()

result := make([]string, 0, 10)
for s := range ExecutePipeline(in, done, stages...) {
result = append(result, s.(string))
}
wg.Wait()

require.Len(t, result, 0)

})
}

func TestChanWrap(t *testing.T) {
t.Run("To end", func(t *testing.T) {
in := make(Bi)
Expand Down
2 changes: 1 addition & 1 deletion hw07_file_copying/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw07_file_copying

go 1.19
go 1.22

require github.com/stretchr/testify v1.9.0

Expand Down
10 changes: 0 additions & 10 deletions hw07_file_copying/go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
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.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions hw08_envdir_tool/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/DimVlas/otus_hw/hw08_envdir_tool

go 1.19
go 1.22

require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
)
Empty file added hw09_struct_validator/.sync
Empty file.
6 changes: 2 additions & 4 deletions hw09_struct_validator/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
module github.com/DimVlas/otus_hw/hw09_struct_validator

go 1.19

go 1.22
require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
)
21 changes: 0 additions & 21 deletions hw09_struct_validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,3 @@ func TestValidate(t *testing.T) {
})
}
}

func TestCheck(t *testing.T) {
// err := checkStruct(struct {
// Id int `validate:"min:1|max:100"`
// Name string `validate:"len:10"`
// }{
// Id: 55,
// Name: "qwerty",
// })

// if err != nil {
// fmt.Println(err)
// }

err := Validate(nil)
if err != nil {
fmt.Println(err)
}

t.Fail()
}
2 changes: 1 addition & 1 deletion hw10_program_optimization/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/fixme_my_friend/hw10_program_optimization

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
2 changes: 1 addition & 1 deletion hw11_telnet_client/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/fixme_my_friend/hw11_telnet_client

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
2 changes: 1 addition & 1 deletion hw12_13_14_15_calendar/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test:
go test -race ./internal/... ./pkg/...

install-lint-deps:
(which golangci-lint > /dev/null) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.50.1
(which golangci-lint > /dev/null) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.57.2

lint: install-lint-deps
golangci-lint run ./...
Expand Down
2 changes: 1 addition & 1 deletion hw12_13_14_15_calendar/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Собираем в гошке
FROM golang:1.19 as build
FROM golang:1.22 as build

ENV BIN_FILE /opt/calendar/calendar-app
ENV CODE_DIR /go/src/
Expand Down
2 changes: 1 addition & 1 deletion hw12_13_14_15_calendar/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/fixme_my_friend/hw12_13_14_15_calendar

go 1.19
go 1.22

0 comments on commit bc7f5a2

Please sign in to comment.