Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to add replace to the generated go.mod #32

Closed
chaudum opened this issue Nov 11, 2021 · 1 comment · Fixed by #33
Closed

Add possibility to add replace to the generated go.mod #32

chaudum opened this issue Nov 11, 2021 · 1 comment · Fixed by #33
Labels
enhancement New feature or request

Comments

@chaudum
Copy link
Contributor

chaudum commented Nov 11, 2021

Certain projects have the need for defining replace directives in their go.mod to build.

I've tried to use the --with argument to pass additional replace directives:

XK6_SKIP_CLEANUP=1 xk6 build \
  --with k8s.io/client-go="k8s.io/client-go v0.21.0" \
  --with k8s.io/api="k8s.io/api v0.21.0" \
  --with github.com/chaudum/xk6-loki="$(pwd)"

This will correctly add replaces in the resulting go.mod:

module k6

go 1.16

replace k8s.io/client-go => k8s.io/client-go v0.21.0

replace k8s.io/api => k8s.io/api v0.21.0

replace github.com/chaudum/xk6-loki => /home/christian/sandbox/chaudum/xk6-loki

require go.k6.io/k6 latest

However it also adds imports in the main.go:

package main

import (
	k6cmd "go.k6.io/k6/cmd"

	// plug in k6 modules here
	// TODO: Create /modules/standard dir structure?
	// _ "go.k6.io/k6/modules/standard"
	_ "k8s.io/client-go"
	_ "k8s.io/api"
	_ "github.com/chaudum/xk6-loki"
)

func main() {
	k6cmd.Execute()
}

The problem with these imports is, that there are no top-level packages for e.g. k8s.io/client-go,
resulting in the following error:

go: finding module for package k8s.io/client-go
k6 imports
	k8s.io/client-go: module k8s.io/client-go@latest found (v0.0.0-00010101000000-000000000000, replaced by k8s.io/client-go@v0.21.0), but does not contain package k8s.io/client-go

Removing the imports and running go mod tidy && go build -o xk6-loki main.go in the build environment manually solves the problem.

I would like to suggest to add an option to add replace directives without adding the package imports to the main.go file. This could for example be done with a separate --replace argument.

@imiric
Copy link
Contributor

imiric commented Nov 11, 2021

Hi, thanks for suggesting this. A new --replace argument does make sense to handle these cases.

Our resources are scarce for new xk6 features right now, but we'll try to get to this in the next few weeks. Otherwise, feel free to propose a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants