pipeline: init

This commit is contained in:
2024-02-15 19:31:43 +03:00
parent 562e6633b3
commit 90d14cd743
5 changed files with 109 additions and 0 deletions

53
pipeline/Makefile Normal file
View File

@ -0,0 +1,53 @@
.DEFAULT_GOAL := help
# ==================================================================================== #
# HELPERS
# ==================================================================================== #
## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
## all: tidy + audit + test/cover
all: generate tidy test lint test/cover
# ==================================================================================== #
# QUALITY CONTROL
# ==================================================================================== #
## tidy: format code and tidy modfile
.PHONY: tidy
tidy:
go fmt ./...
goimports -local=$(shell cat go.mod | grep module | awk '{print $$2}')/ -w .
go mod tidy -v
## audit: run quality control checks
.PHONY: lint
lint:
go mod verify
go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v ./...
# ==================================================================================== #
# DEVELOPMENT
# ==================================================================================== #
## generate: run all generators
.PHONY: generate
generate:
go generate ./...
## test: run all tests
.PHONY: test
test:
go test -race -buildvcs ./...
## test/cover: run all tests and display coverage
.PHONY: test/cover
test/cover:
go test -race -buildvcs -coverprofile=/tmp/coverage.out ./...
go tool cover -html=/tmp/coverage.out

11
pipeline/go.mod Normal file
View File

@ -0,0 +1,11 @@
module pipeline
go 1.21.6
require github.com/stretchr/testify v1.8.4
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
)

10
pipeline/go.sum Normal file
View File

@ -0,0 +1,10 @@
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.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
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=

14
pipeline/main.go Normal file
View File

@ -0,0 +1,14 @@
package main
func Pipe[In any, Out any](in <-chan In, pipe func(In) Out) <-chan Out {
out := make(chan Out)
go func() {
for n := range in {
out <- pipe(n)
}
close(out)
}()
return out
}

21
pipeline/main_test.go Normal file
View File

@ -0,0 +1,21 @@
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPipe(t *testing.T) {
a := make(chan int, 1)
pipe := func(in int) int {
return in * 2
}
b := Pipe(a, pipe)
a <- 5
close(a)
assert.Equal(t, 10, <-b)
}