Skip to content

Commit

Permalink
build: checkout addons in scripts/test if necessary
Browse files Browse the repository at this point in the history
#708 moved
pkg/config/templates/rancherd-22-addons.yaml to a separate
"addons" repo, and added code to `scripts/build` to clone this
repo during build and copy that yaml file to ./pkg/config/templates.
So everything works fine if you run `make` or `make ci`.  However,
if you just run `make test` by itself (which you might do during
development), rancherd-22-addons.yaml isn't available, and the tests
fail with:

```
Running tests
--- FAIL: TestConvertToCos_SSHKeysInYipNetworkStage (0.00s)
    cos_test.go:71:
        	Error Trace:	/go/src/github.com/harvester/harvester-installer/pkg/config/cos_test.go:71
        	Error:      	Received unexpected error:
        	            	open templates/rancherd-22-addons.yaml: file does not exist
        	Test:       	TestConvertToCos_SSHKeysInYipNetworkStage
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x731164]
```

We can fix this by duplicating the addons clone code from `scripts/build`
into `scripts/test`.  This has no impact on normal builds (`make` or
`make ci`) because the addons repo has already been cloned by
`scripts/build` in that case.

Related issue: harvester/harvester#4937

Signed-off-by: Tim Serong <[email protected]>
  • Loading branch information
tserong committed May 15, 2024
1 parent 71247f7 commit 5cdf312
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ set -e

cd $(dirname $0)/..

# duplicated from scripts/build, so that we can run `make test` standalone
addons_path=../addons
if [ ! -d ${addons_path} ];then
echo "No existed addons source. Pulling..."
git clone --branch main --single-branch --depth 1 https://github.com/harvester/addons.git ../addons
fi
cp ${addons_path}/pkg/templates/*.yaml ./pkg/config/templates

echo Running tests
go test -cover -tags=test ./pkg/...

0 comments on commit 5cdf312

Please sign in to comment.