Skip to content

Commit

Permalink
Working tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Jul 3, 2024
1 parent 25c2f10 commit 00b3533
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
39 changes: 38 additions & 1 deletion test/unit/codegen_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
package unit_test

import "testing"
import (
"os"
"strings"
"testing"

"knative.dev/hack/pkg/utest/require"
)

func TestCodegen(t *testing.T) {
t.Parallel()
tmpdir := t.TempDir()
execPermission := os.FileMode(0o755)
require.NoError(t, os.MkdirAll(tmpdir+"/go/bin", execPermission))
require.NoError(t, os.WriteFile(
tmpdir+"/go/bin/deepcopy-gen",
[]byte(strings.Join([]string{"#!/bin/bash",
`git restore test/e2e/apis/hack/v1alpha1/zz_generated.deepcopy.go`,
`echo "Deepcopy generation complete"`,
"exit 248"}, "\n")),
execPermission))
sc := newShellScript(
envs(map[string]string{"TMPDIR": tmpdir}),
loadFile("source-codegen-library.bash"),
mockGo(),
)
Expand All @@ -13,6 +30,26 @@ func TestCodegen(t *testing.T) {
"knative.dev/hack/test/e2e/apis/hack/v1alpha1/generated " +
"knative.dev/hack/test/e2e/apis " +
"hack:v1alpha1",
retcode: retcode(248),
stdout: equal(`WARNING: generate-groups.sh is deprecated.
WARNING: Please use k8s.io/code-generator/kube_codegen.sh instead.
WARNING: generate-internal-groups.sh is deprecated.
WARNING: Please use k8s.io/code-generator/kube_codegen.sh instead.
go install k8s.io/code-generator/cmd/applyconfiguration-gen k8s.io/code-generator/cmd/client-gen k8s.io/code-generator/cmd/conversion-gen k8s.io/code-generator/cmd/deepcopy-gen k8s.io/code-generator/cmd/defaulter-gen k8s.io/code-generator/cmd/informer-gen k8s.io/code-generator/cmd/lister-gen k8s.io/code-generator/cmd/openapi-gen
Generating deepcopy funcs
Deepcopy generation complete
`,
),
stderr: equal(strings.TrimLeft(`
╭───────────────────────────────────────────────────────────╮
│ │
│ WARN: Failed to determine the knative.dev/pkg package │
│ │
╰───────────────────────────────────────────────────────────╯
--- Cleaning up generated code
`, "\n")),
}}
for i := range tcs {
tc := tcs[i]
Expand Down
4 changes: 1 addition & 3 deletions test/unit/scripts/source-codegen-library.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@

set -Eeuo pipefail

pushd "$(dirname "${BASH_SOURCE[0]:-$0}")/../.." > /dev/null
# shellcheck disable=SC1090
source "$(go run ./cmd/script codegen-library.sh)"
popd > /dev/null
source "$(go run "$(realpath "$(dirname "$0")/../../cmd/script")" codegen-library.sh)"

0 comments on commit 00b3533

Please sign in to comment.