Hi all
I am building the shell project in Golang. But I am unable to test it on local Windows environment. Installed Golang version : 1.23.4
Golang version used by Codecrafters tester : 1.22.10
I changed the version in the go.mod file to 1.23.4 and run go mod tidy after that. But no packages are added to go.mod file. I need some help figuring out the issue in my local setup. TIA!
Hi @ruchisaluja, could you confirm what error messages you’re seeing?
Please note that our testers are run on Linux, so you might need to install WSL to test on Windows.
@andy1li
I also try to run tests locally with golang. I just get back to my first submission for a challenge and try to create a test file serve_test.go
. Here the code:
When I try to launch the test with the command go test app/server_test.go
, I get:
# command-line-arguments [command-line-arguments.test]
app/server_test.go:9:9: undefined: Hello
FAIL command-line-arguments [build failed]
FAIL
You can see that I tried to import the main module at the 5 line of server_test.go
but it has no chance to work this way.
I also don’t find documentation of this topic at:
Do you have any clue for me too be able to run test locally in golang? It would enable users to write code in a TDD fashion which is a good way to develop a project
Hi @andy1li, I just wonder if you had time to read my message and if it was understandable.
Do you think it is in your roadmap for golang?
I finally got a synthetic example where I can run a golang unit test in a codecrafters challenge. Here is an image where you can see every part of my tiny test example:
In the pink rectangle, you can see that I have 2 files in my app
directory, server.go
and server_test.go
. In the green rectangles, you can see I have a functionToTest()
that returns a string and a TestHello()
that tests this function. So now, at the root of the repository, I can run this test with the following command:
$ go test ./app
ok github.com/codecrafters-io/kafka-starter-go/app 0.003s
If you want more details:
$ go test -v ./app
=== RUN TestHello
--- PASS: TestHello (0.00s)
PASS
ok github.com/codecrafters-io/kafka-starter-go/app 0.002s
What is confusing is that if you give directly the path of the test source file, you will get this error:
$ go test ./app/server_test.go
# command-line-arguments [command-line-arguments.test]
app/server_test.go:8:9: undefined: functionToTest
FAIL command-line-arguments [build failed]
FAIL
You want to test a subdirectory, foo
, of app
directory, you just have to give its path on the command line:
$ go test ./app/foo
@andy1li IMHO, this topic is solved.
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.