Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build & Test Pairing
on:
push:
branches:
- master
tags-ignore:
- "*.*"
paths:
- "pairing/**"
pull_request:
branches:
- master
paths:
- "pairing/**"

jobs:
test:
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ./pairing
strategy:
matrix:
os: [ ubuntu-latest ]
name: Test

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: ./pairing/go.mod

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.1.6
skip-pkg-cache: true
skip-build-cache: true
working-directory: ./pairing
args: --config=./.golangci.yml --verbose

- name: Test
run: |
make test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,7 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# Ignore build output artifacts for the pairing module
pairing/build/_output/

# End of https://www.gitignore.io/api/vim,git,macos,linux,emacs,windows,eclipse,intellij+all,visualstudiocode
62 changes: 62 additions & 0 deletions pairing/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: "2"
linters:
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- durationcheck
- errchkjson
- errorlint
- exhaustive
- gocheckcompilerdirectives
- gochecksumtype
- gocyclo
- gosec
- gosmopolitan
- loggercheck
- makezero
- misspell
- musttag
- nilerr
- nilnesserr
- protogetter
- reassign
- recvcheck
- revive
- rowserrcheck
- spancheck
- sqlclosecheck
- testifylint
- unparam
- zerologlint
disable:
- contextcheck
- noctx
settings:
revive:
rules:
- name: dot-imports
disabled: true
unparam:
check-exported: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
5 changes: 5 additions & 0 deletions pairing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# It's necessary to set this because some environments don't link sh -> bash.
SHELL := /bin/bash

include ./make/*.mk
.DEFAULT_GOAL := help
5 changes: 5 additions & 0 deletions pairing/dummy/func.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dummy

func Add(a, b int) int {
return a + b
}
13 changes: 13 additions & 0 deletions pairing/dummy/func_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dummy

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestAdd(t *testing.T) {
result := Add(2, 3)

assert.Equal(t, 5, result)
}
11 changes: 11 additions & 0 deletions pairing/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/codeready-toolchain/pairing

go 1.22.12

require github.com/stretchr/testify v1.10.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
)
10 changes: 10 additions & 0 deletions pairing/go.sum
Original file line number Diff line number Diff line change
@@ -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.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.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=
12 changes: 12 additions & 0 deletions pairing/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"fmt"

"github.com/codeready-toolchain/pairing/dummy"
)

func main() {
result := dummy.Add(2, 3)
fmt.Printf("2 + 3 = %d\n", result)
}
29 changes: 29 additions & 0 deletions pairing/make/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
GO_PACKAGE_ORG_NAME ?= codeready-toolchain
GO_PACKAGE_REPO_NAME ?= pairing
GO_PACKAGE_PATH ?= github.com/${GO_PACKAGE_ORG_NAME}/${GO_PACKAGE_REPO_NAME}
goarch ?= amd64

BIN_DIR = $(OUT_DIR)/bin
.PHONY: build
## Build the operator
build: GO_COMMAND=build
build: GO_EXTRA_FLAGS=-o $(BIN_DIR)/
build: clean-bin run-go

.PHONY: install
## installs the binary executable
install: GO_COMMAND=install
install: run-go

run-go:
$(Q)CGO_ENABLED=0 \
env GOOS=linux GOARCH=${goarch} go ${GO_COMMAND} ${V_FLAG} \
-ldflags "-X ${GO_PACKAGE_PATH}/pkg/version.Commit=${GIT_COMMIT_ID} -X ${GO_PACKAGE_PATH}/pkg/version.BuildTime=${BUILD_TIME}" \
${GO_EXTRA_FLAGS} ${GO_PACKAGE_PATH}/...

.PHONY: lint
lint:
ifeq (, $(shell which golangci-lint 2>/dev/null))
$(error "golangci-lint not found in PATH. Please install it using instructions on https://golangci-lint.run/usage/install/#local-installation")
endif
golangci-lint ${V_FLAG} run --config=./.golangci.yml --verbose ./...
9 changes: 9 additions & 0 deletions pairing/make/clean.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.PHONY: clean
clean: clean-bin
$(Q)-rm -rf ${V_FLAG} ./vendor
$(Q)-rm -rf ($COV_DIR)
$(Q)go clean ${X_FLAG} ./...

.PHONY: clean-bin
clean-bin:
@rm -rf $(BIN_DIR) 2>/dev/null || true
5 changes: 5 additions & 0 deletions pairing/make/out.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Create output directory for artifacts and test results. `./build/_output` is supposed to
# be a safe place for all targets to write to while knowing that all content
# inside of `./build/_output` is wiped once "make clean" is run.
OUT_DIR := ./build/_output
$(shell mkdir -p $(OUT_DIR))
17 changes: 17 additions & 0 deletions pairing/make/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.PHONY: test
test: build
@echo "running the pairing unit tests..."
go test -v -failfast ./...


# Output directory for coverage information
COV_DIR = $(OUT_DIR)/coverage

.PHONY: test-with-coverage
## runs the tests with coverage
test-with-coverage:
@echo "running the unit tests with coverage..."
@-mkdir -p $(COV_DIR)
@-rm $(COV_DIR)/coverage.txt
$(Q)go test -vet off ${V_FLAG} $(shell go list ./... | grep -v /cmd/manager) -coverprofile=$(COV_DIR)/coverage.txt -covermode=atomic ./...

24 changes: 24 additions & 0 deletions pairing/make/verbose.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# When you run make VERBOSE=1 (the default), executed commands will be printed
# before executed. If you run make VERBOSE=2 verbose flags are turned on and
# quiet flags are turned off for various commands. Use V_FLAG in places where
# you can toggle on/off verbosity using -v. Use Q_FLAG in places where you can
# toggle on/off quiet mode using -q. Use S_FLAG where you want to toggle on/off
# silence mode using -s...
VERBOSE ?= 1
Q = @
Q_FLAG = -q
QUIET_FLAG = --quiet
V_FLAG =
S_FLAG = -s
X_FLAG =
ifeq ($(VERBOSE),1)
Q =
endif
ifeq ($(VERBOSE),2)
Q =
Q_FLAG =
QUIET_FLAG =
S_FLAG =
V_FLAG = -v
X_FLAG = -x
endif