Skip to content

Commit

Permalink
Mock truncate of go.work.sum to avoid removing it after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Jul 18, 2024
1 parent 3a99010 commit f617a18
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ function go_update_deps() {
function __clean_goworksum_if_exists() {
if [ -f "$REPO_ROOT_DIR/go.work.sum" ]; then
log.step 'Cleaning the go.work.sum file'
true > "$REPO_ROOT_DIR/go.work.sum"
truncate --size 0 "$REPO_ROOT_DIR/go.work.sum"
fi
}

Expand Down
6 changes: 3 additions & 3 deletions test/unit/presubmit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func TestPresubmitTestMainFunc(t *testing.T) {
contains("Build tests for knative.dev/hack/schema"),
contains("Build tests for knative.dev/hack"),
contains("Checking that go code builds"),
contains("go test -vet=off -tags e2e,library -exec echo ./..."),
contains("go test -vet=off -tags -exec echo ./..."),
contains("go run knative.dev/test-infra/tools/kntest/cmd/kntest@latest" +
contains("👻 go test -vet=off -tags e2e,library -exec echo ./..."),
contains("👻 go test -vet=off -tags -exec echo ./..."),
contains("👻 go run knative.dev/test-infra/tools/kntest/cmd/kntest@latest" +
" junit --suite=_build_tests --name=Check_Licenses --err-msg= --dest="),
header("BUILD TESTS PASSED"),
},
Expand Down
22 changes: 14 additions & 8 deletions test/unit/update_deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ func TestUpdateDeps(t *testing.T) {
sc := newShellScript(
loadFile("source-library.bash"),
mockGo(),
mockBinary("truncate", response{
args: startsWith{"--size 0"},
response: simply(""),
}),
)
tcs := []testCase{{
name: "go_update_deps --unknown",
Expand All @@ -24,24 +28,26 @@ func TestUpdateDeps(t *testing.T) {
contains("Golang module: knative.dev/hack"),
contains("Checking licenses"),
contains("Removing unwanted vendor files"),
contains("go mod tidy"),
contains("go run github.com/google/go-licenses@v1.6.0 check"),
contains("👻 go mod tidy"),
contains("👻 go run github.com/google/go-licenses@v1.6.0 check"),
contains("👻 go mod download -x"),
},
}, {
name: "go_update_deps --upgrade",
stdout: []check{
contains("go run knative.dev/toolbox/buoy@latest float ./go.mod " +
"--release v9000.1 --domain knative.dev"),
contains("👻 go run knative.dev/toolbox/buoy@latest float " +
"./go.mod --release v9000.1 --domain knative.dev"),
},
}, {
name: "go_update_deps --upgrade --release 1.25 --module-release 0.28",
stdout: []check{
contains("go run knative.dev/toolbox/buoy@latest float ./go.mod " +
"--release 1.25 --domain knative.dev --module-release 0.28"),
contains("👻 go run knative.dev/toolbox/buoy@latest float " +
"./go.mod --release 1.25 --domain knative.dev " +
"--module-release 0.28"),
},
}}
for _, tc := range tcs {
tc := tc
for i := range tcs {
tc := tcs[i]
t.Run(tc.name, tc.test(sc))
}
}

0 comments on commit f617a18

Please sign in to comment.