test: Add workaround for zinit installation in tests

- Added a workaround to download and execute zinit if it's not found in the path.
- This is necessary because the zinit installer cannot be imported due to a circular dependency.
- This ensures that the tests can run reliably even without zinit being pre-installed.

Co-authored-by: mahmmoud.hassanein <mahmmoud.hassanein@gmail.com>
This commit is contained in:
2025-01-27 12:31:00 +02:00
parent 85ac9e5104
commit 623f1a289e

View File

@@ -2,11 +2,35 @@ module zinit
import os import os
import time import time
import freeflowuniverse.herolib.core
import freeflowuniverse.herolib.osal
fn test_zinit() { fn test_zinit() {
if !core.is_linux()! {
// zinit is only supported on linux
return
}
// TODO: use zinit installer to install zinit
// this is a workaround since we can't import zinit installer due to circular dependency
zinit_version := os.execute('zinit --version')
if zinit_version.exit_code != 0 {
release_url := 'https://github.com/threefoldtech/zinit/releases/download/v0.2.14/zinit'
mut dest := osal.download(
url: release_url
minsize_kb: 2000
reset: true
dest: '/tmp/zinit'
)!
chmod_cmd := os.execute('chmod +x /tmp/zinit')
assert chmod_cmd.exit_code == 0, 'failed to chmod +x /tmp/zinit: ${chmod_cmd.output}'
}
this_dir := os.dir(@FILE) this_dir := os.dir(@FILE)
// you need to have zinit in your path to run this test // you need to have zinit in your path to run this test
spawn os.execute('zinit -s ${this_dir}/zinit/zinit.sock init -c ${this_dir}/zinit') spawn os.execute('/tmp/zinit -s ${this_dir}/zinit/zinit.sock init -c ${this_dir}/zinit')
time.sleep(time.second) time.sleep(time.second)
client := new_rpc_client(socket_path: '${this_dir}/zinit/zinit.sock') client := new_rpc_client(socket_path: '${this_dir}/zinit/zinit.sock')