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

CC-753 upgrade tester utils #45

Merged
merged 14 commits into from
Sep 26, 2023
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dist
__pycache__
vendor
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ test:

test_with_git: build
CODECRAFTERS_SUBMISSION_DIR=$(shell pwd)/internal/test_helpers/pass_all \
CODECRAFTERS_CURRENT_STAGE_SLUG="clone_repository" \
CODECRAFTERS_COURSE_PAGE_URL="test" \
CODECRAFTERS_TEST_CASES_JSON="[{"slug":"init","tester_log_prefix":"stage-1","title":"Stage #1: Initialize the .git directory"},{"slug":"read_blob","tester_log_prefix":"stage-2","title":"Stage #2: Read a blob object"},{"slug":"create_blob","tester_log_prefix":"stage-3","title":"Stage #3: Create a blob object"},{"slug":"read_tree","tester_log_prefix":"stage-4","title":"Stage #4: Read a tree object"},{"slug":"write_tree","tester_log_prefix":"stage-5","title":"Stage #5: Write a tree object"},{"slug":"create_commit","tester_log_prefix":"stage-6","title":"Stage #6: Create a commit"},{"slug":"clone_repository","tester_log_prefix":"stage-7","title":"Stage #7: Clone a repository"}]" \
dist/main.out

copy_course_file:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a program that validates your progress on the Git challenge.

- Following environment variables:
- `CODECRAFTERS_SUBMISSION_DIR` - root of the user's code submission
- `CODECRAFTERS_CURRENT_STAGE_SLUG` - current stage the user is on
- `CODECRAFTERS_TEST_CASES_JSON` - test cases in JSON format

# User code requirements

Expand Down
32 changes: 25 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
module github.com/codecrafters-io/git-tester

go 1.14
go 1.20

require (
github.com/codecrafters-io/tester-utils v0.1.46
github.com/fatih/color v1.13.0 // indirect
github.com/codecrafters-io/tester-utils v0.2.0
github.com/go-git/go-billy/v5 v5.0.0
github.com/go-git/go-git/v5 v5.0.0
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/xanzy/ssh-agent v0.2.1 // indirect
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect
golang.org/x/sys v0.12.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
41 changes: 17 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/codecrafters-io/tester-utils v0.1.46 h1:kchXzxm6FLrR06Ab1/0iaOi9JiHzosCTzcg6vlw4yXg=
github.com/codecrafters-io/tester-utils v0.1.46/go.mod h1:VifsWEvXrRB18l2+rkE7gwuzWRhGX4AffJ01VTgMYfw=
github.com/codecrafters-io/tester-utils v0.2.0 h1:LHGrqE5wVaOoJ7aSa5vS93W3ToR7/tnHt3ATIt9z8gE=
github.com/codecrafters-io/tester-utils v0.2.0/go.mod h1:BeSLyqBpFxUwIm41QlnuRG7ZsabBXWE2Ga3LMFUXAPM=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
Expand All @@ -39,13 +37,11 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
Expand All @@ -60,8 +56,8 @@ github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand All @@ -74,13 +70,11 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand All @@ -95,6 +89,5 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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: 6 additions & 6 deletions internal/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

tester_utils "github.com/codecrafters-io/tester-utils"
executable "github.com/codecrafters-io/tester-utils/executable"
)

func assertEqual(actual string, expected string) error {
Expand All @@ -15,7 +15,7 @@ func assertEqual(actual string, expected string) error {
return nil
}

func assertStdout(result tester_utils.ExecutableResult, expected string) error {
func assertStdout(result executable.ExecutableResult, expected string) error {
actual := string(result.Stdout)
if expected != actual {
return fmt.Errorf("Expected %q as stdout, got: %q", expected, actual)
Expand All @@ -24,7 +24,7 @@ func assertStdout(result tester_utils.ExecutableResult, expected string) error {
return nil
}

func assertStderr(result tester_utils.ExecutableResult, expected string) error {
func assertStderr(result executable.ExecutableResult, expected string) error {
actual := string(result.Stderr)
if expected != actual {
return fmt.Errorf("Expected %q as stderr, got: %q", expected, actual)
Expand All @@ -33,7 +33,7 @@ func assertStderr(result tester_utils.ExecutableResult, expected string) error {
return nil
}

func assertStdoutContains(result tester_utils.ExecutableResult, expectedSubstring string) error {
func assertStdoutContains(result executable.ExecutableResult, expectedSubstring string) error {
actual := string(result.Stdout)
if !strings.Contains(actual, expectedSubstring) {
return fmt.Errorf("Expected stdout to contain %q, got: %q", expectedSubstring, actual)
Expand All @@ -42,7 +42,7 @@ func assertStdoutContains(result tester_utils.ExecutableResult, expectedSubstrin
return nil
}

func assertStderrContains(result tester_utils.ExecutableResult, expectedSubstring string) error {
func assertStderrContains(result executable.ExecutableResult, expectedSubstring string) error {
actual := string(result.Stderr)
if !strings.Contains(actual, expectedSubstring) {
return fmt.Errorf("Expected stderr to contain %q, got: %q", expectedSubstring, actual)
Expand All @@ -51,7 +51,7 @@ func assertStderrContains(result tester_utils.ExecutableResult, expectedSubstrin
return nil
}

func assertExitCode(result tester_utils.ExecutableResult, expected int) error {
func assertExitCode(result executable.ExecutableResult, expected int) error {
actual := result.ExitCode
if expected != actual {
return fmt.Errorf("Expected %d as exit code, got: %d", expected, actual)
Expand Down
2 changes: 2 additions & 0 deletions internal/stage_clone_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func randomRepo() TestRepo {
}

func testCloneRepository(stageHarness *tester_utils.StageHarness) error {
initRandom()

logger := stageHarness.Logger
executable := stageHarness.Executable

Expand Down
2 changes: 2 additions & 0 deletions internal/stage_create_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

func testCreateBlob(stageHarness *tester_utils.StageHarness) error {
initRandom()

logger := stageHarness.Logger
executable := stageHarness.Executable

Expand Down
2 changes: 2 additions & 0 deletions internal/stage_create_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
)

func testCreateCommit(stageHarness *tester_utils.StageHarness) error {
initRandom()

logger := stageHarness.Logger
executable := stageHarness.Executable

Expand Down
16 changes: 14 additions & 2 deletions internal/stage_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package internal

import (
"math/rand"
"os"
"strconv"
"strings"
"time"
)
Expand All @@ -19,8 +21,18 @@ var randomWords = []string{
"vanilla",
}

func init() {
rand.Seed(time.Now().UnixNano())
func initRandom() {
if seed := os.Getenv("CODECRAFTERS_RANDOM_SEED"); seed != "" {
seedInt, err := strconv.Atoi(seed)

if err != nil {
panic(err)
}

rand.Seed(int64(seedInt))
} else {
rand.Seed(time.Now().UnixNano())
}
}

func randomWord() string {
Expand Down
7 changes: 5 additions & 2 deletions internal/stage_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"os"
"path"

logger "github.com/codecrafters-io/tester-utils/logger"
tester_utils "github.com/codecrafters-io/tester-utils"
)

func testInit(stageHarness *tester_utils.StageHarness) error {
initRandom()

logger := stageHarness.Logger
executable := stageHarness.Executable

Expand Down Expand Up @@ -88,12 +91,12 @@ func assertFileExistsInDir(parent string, child string) error {
return nil
}

func logDebugTree(logger *tester_utils.Logger, dir string) {
func logDebugTree(logger *logger.Logger, dir string) {
logger.Debugf("Files found in directory: ")
doLogDebugTree(logger, dir, " ")
}

func doLogDebugTree(logger *tester_utils.Logger, dir string, prefix string) {
func doLogDebugTree(logger *logger.Logger, dir string, prefix string) {
entries, err := ioutil.ReadDir(dir)
if err != nil {
panic(err)
Expand Down
2 changes: 2 additions & 0 deletions internal/stage_read_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
)

func testReadBlob(stageHarness *tester_utils.StageHarness) error {
initRandom()

logger := stageHarness.Logger
executable := stageHarness.Executable

Expand Down
2 changes: 2 additions & 0 deletions internal/stage_read_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
)

func testReadTree(stageHarness *tester_utils.StageHarness) error {
initRandom()

logger := stageHarness.Logger
executable := stageHarness.Executable

Expand Down
18 changes: 17 additions & 1 deletion internal/stage_write_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (
"math/rand"
"os"
"os/exec"
"strconv"
"strings"
"time"

tester_utils "github.com/codecrafters-io/tester-utils"
)

func testWriteTree(stageHarness *tester_utils.StageHarness) error {
initRandom()

logger := stageHarness.Logger
executable := stageHarness.Executable

Expand All @@ -33,7 +36,20 @@ func testWriteTree(stageHarness *tester_utils.StageHarness) error {

logger.Debugf("Creating some files & directories")

seed := time.Now().UnixNano()
var seed int64

if seedStr := os.Getenv("CODECRAFTERS_RANDOM_SEED"); seedStr != "" {
seedInt, err := strconv.Atoi(seedStr)

if err != nil {
panic(err)
}

seed = int64(seedInt)
} else {
seed = time.Now().UnixNano()
}

err = generateFiles(tempDir, seed)
if err != nil {
panic(err)
Expand Down
Loading
Loading