Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Upgrading dependencies and adding standard CI
Browse files Browse the repository at this point in the history
Fixes #14

Signed-off-by: Paul Balogh <[email protected]>
  • Loading branch information
javaducky committed Apr 7, 2023
1 parent 9beab53 commit 0bf274e
Show file tree
Hide file tree
Showing 13 changed files with 439 additions and 434 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: CI
on:
# Enable manually triggering this workflow via the API or web UI
workflow_dispatch:
push:
branches:
- main
tags:
- v*
pull_request:

defaults:
run:
shell: bash

jobs:

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: Retrieve golangci-lint version
run: |
echo "Version=$(head -n 1 "${GITHUB_WORKSPACE}/.golangci.yml" | tr -d '# ')" >> $GITHUB_OUTPUT
id: version
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: ${{ steps.version.outputs.Version }}
only-new-issues: true

test-go-versions:
strategy:
fail-fast: false
matrix:
go-version: [1.18.x, 1.19.x, 1.20.x, tip]
platform: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go ${{ matrix.go-version }}
if: matrix.go-version != 'tip'
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Install Go stable
if: matrix.go-version == 'tip'
uses: actions/setup-go@v3
with:
go-version: 1.x
- name: Install Go tip
shell: bash
if: matrix.go-version == 'tip'
run: |
go install golang.org/dl/gotip@latest
gotip download
echo "GOROOT=$HOME/sdk/gotip" >> "$GITHUB_ENV"
echo "GOPATH=$HOME/go" >> "$GITHUB_ENV"
echo "$HOME/go/bin" >> "$GITHUB_PATH"
echo "$HOME/sdk/gotip/bin" >> "$GITHUB_PATH"
- name: Run tests
run: |
which go
go version
go test -race -timeout 800s ./...
test-build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: Check build
run: |
go version
pwd && ls -l
go install go.k6.io/xk6/cmd/xk6@master
MODULE_NAME=`go list -m`
GOPRIVATE="go.k6.io/k6" xk6 build \
--output ./k6ext \
--with $MODULE_NAME="."
./k6ext version
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
.DS_Store
k6
129 changes: 129 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# v1.52.2
# Please don't remove the first line. It uses in CI to determine the golangci version
run:
deadline: 5m

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# We want to try and improve the comments in the k6 codebase, so individual
# non-golint items from the default exclusion list will gradually be addded
# to the exclude-rules below
exclude-use-default: false

exclude-rules:
# Exclude duplicate code and function length and complexity checking in test
# files (due to common repeats and long functions in test code)
- path: _(test|gen)\.go
linters:
- cyclop
- dupl
- gocognit
- funlen
- lll
- linters:
- paralleltest # false positive: https://github.com/kunwardeep/paralleltest/issues/8.
text: "does not use range value in test Run"
- linters:
- forbidigo
text: 'use of `os\.(SyscallError|Signal|Interrupt)` forbidden'

linters-settings:
nolintlint:
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: false
exhaustive:
default-signifies-exhaustive: true
govet:
check-shadowing: true
cyclop:
max-complexity: 25
maligned:
suggest-new: true
dupl:
threshold: 150
goconst:
min-len: 10
min-occurrences: 4
funlen:
lines: 80
statements: 60
forbidigo:
forbid:
- '^(fmt\\.Print(|f|ln)|print|println)$'
# Forbid everything in os, except os.Signal and os.SyscalError
- '^os\.(.*)$(# Using anything except Signal and SyscallError from the os package is forbidden )?'
# Forbid everything in syscall except the uppercase constants
- '^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )?'
- '^logrus\.Logger$'

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- cyclop
- depguard
- dogsled
- dupl
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gocheckcompilerdirectives
- gochecknoglobals
- gocognit
- goconst
- gocritic
- gofmt
- gofumpt
- goimports
- gomoddirectives
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- lll
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- prealloc
- predeclared
- promlinter
- revive
- reassign
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
fast: false
75 changes: 75 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting our Developer Relations team, [email protected].

All complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
MAKEFLAGS += --silent

all: clean format test build

## help: Prints a list of available build targets.
help:
echo "Usage: make <OPTIONS> ... <TARGETS>"
echo ""
echo "Available targets are:"
echo ''
sed -n 's/^##//p' ${PWD}/Makefile | column -t -s ':' | sed -e 's/^/ /'
echo
echo "Targets run by default are: `sed -n 's/^all: //p' ./Makefile | sed -e 's/ /, /g' | sed -e 's/\(.*\), /\1, and /'`"

## clean: Removes any previously created build artifacts.
clean:
rm -f ./k6

## build: Builds a custom 'k6' with the local extension.
build:
go install go.k6.io/xk6/cmd/xk6@latest
xk6 build --with $(shell go list -m)=.

## format: Applies Go formatting to code.
format:
go fmt ./...

## test: Executes any unit tests.
test:
go test -cover -race ./...

.PHONY: build clean format help test
19 changes: 3 additions & 16 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
> ### ⚠️ This is a proof of concept
>
> As this is a proof of concept, it won't be supported by the k6 team.
> It may also break in the future as xk6 evolves. USE AT YOUR OWN RISK!
> Any issues with the tool should be raised [here](https://github.com/grafana/xk6-docker/issues).
</br>
</br>

<div align="center">

# xk6-docker
A k6 extension for using of Docker CLI in testing. Built for [k6](https://go.k6.io/k6) using [xk6](https://github.com/grafana/xk6).

</div>

## Build

To build a `k6` binary with this extension, first ensure you have the prerequisites:
Expand All @@ -40,8 +27,8 @@ import containers from 'k6/x/docker/containers';

export default function () {
containers.list().forEach((container) => {
console.log(container.id.substring(0, 10)));
})
console.log(container.id.substring(0, 10));
});
}
```

Expand Down Expand Up @@ -78,4 +65,4 @@ default ✓ [======================================] 1 VUs 00m00.0s/10m0s 1/1
```

Inspect examples folder for more details.
Inspect [`examples`](examples) folder for more details.
8 changes: 5 additions & 3 deletions containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

// Containers is a structure with all docker containers functions
type Containers struct {
Version string
Client *client.Client
Client *client.Client
}

// SetupClient for filling in Docker client instance
Expand Down Expand Up @@ -62,7 +61,10 @@ func (d *Containers) Logs(containerID string, options types.ContainerLogsOptions
return "", err
}

buf.ReadFrom(response)
_, err = buf.ReadFrom(response)
if err != nil {
return "", err
}
return buf.String(), nil
}

Expand Down
Loading

0 comments on commit 0bf274e

Please sign in to comment.