docs: Formatting the code
This commit is contained in:
@@ -13,12 +13,12 @@ fn test_json_generation() {
|
||||
mut configs := map[string]&CrunConfig{}
|
||||
mut config := new(mut configs, name: 'test')!
|
||||
json_str := config.to_json()!
|
||||
|
||||
|
||||
// Parse back to verify structure
|
||||
parsed := json.decode(map[string]json.Any, json_str)!
|
||||
|
||||
|
||||
assert parsed['ociVersion']! as string == '1.0.2'
|
||||
|
||||
|
||||
process := parsed['process']! as map[string]json.Any
|
||||
assert process['terminal']! as bool == true
|
||||
}
|
||||
@@ -26,11 +26,11 @@ fn test_json_generation() {
|
||||
fn test_configuration_methods() {
|
||||
mut configs := map[string]&CrunConfig{}
|
||||
mut config := new(mut configs, name: 'test')!
|
||||
|
||||
|
||||
config.set_command(['/bin/echo', 'hello'])
|
||||
.set_working_dir('/tmp')
|
||||
.set_hostname('test-host')
|
||||
|
||||
|
||||
assert config.spec.process.args == ['/bin/echo', 'hello']
|
||||
assert config.spec.process.cwd == '/tmp'
|
||||
assert config.spec.hostname == 'test-host'
|
||||
@@ -39,10 +39,10 @@ fn test_configuration_methods() {
|
||||
fn test_validation() {
|
||||
mut configs := map[string]&CrunConfig{}
|
||||
mut config := new(mut configs, name: 'test')!
|
||||
|
||||
|
||||
// Should validate successfully with defaults
|
||||
config.validate()!
|
||||
|
||||
|
||||
// Should fail with empty args
|
||||
config.spec.process.args = []
|
||||
if _ := config.validate() {
|
||||
@@ -55,20 +55,20 @@ fn test_validation() {
|
||||
fn test_heropods_compatibility() {
|
||||
mut configs := map[string]&CrunConfig{}
|
||||
mut config := new(mut configs, name: 'heropods')!
|
||||
|
||||
|
||||
// The default config should match heropods template structure
|
||||
json_str := config.to_json()!
|
||||
parsed := json.decode(map[string]json.Any, json_str)!
|
||||
|
||||
|
||||
// Check key fields match template
|
||||
assert parsed['ociVersion']! as string == '1.0.2'
|
||||
|
||||
|
||||
process := parsed['process']! as map[string]json.Any
|
||||
assert process['noNewPrivileges']! as bool == true
|
||||
|
||||
|
||||
capabilities := process['capabilities']! as map[string]json.Any
|
||||
bounding := capabilities['bounding']! as []json.Any
|
||||
assert 'CAP_AUDIT_WRITE' in bounding.map(it as string)
|
||||
assert 'CAP_KILL' in bounding.map(it as string)
|
||||
assert 'CAP_NET_BIND_SERVICE' in bounding.map(it as string)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn (config CrunConfig) to_json() !string {
|
||||
// Convenience method to save JSON to file
|
||||
pub fn (config CrunConfig) save_to_file(path string) ! {
|
||||
json_content := config.to_json()!
|
||||
|
||||
|
||||
mut file := pathlib.get_file(path: path, create: true)!
|
||||
file.write(json_content)!
|
||||
}
|
||||
@@ -21,15 +21,15 @@ pub fn (config CrunConfig) validate() ! {
|
||||
if config.spec.oci_version == '' {
|
||||
return error('ociVersion cannot be empty')
|
||||
}
|
||||
|
||||
|
||||
if config.spec.process.args.len == 0 {
|
||||
return error('process.args cannot be empty')
|
||||
}
|
||||
|
||||
|
||||
if config.spec.root.path == '' {
|
||||
return error('root.path cannot be empty')
|
||||
}
|
||||
|
||||
|
||||
// Validate that required capabilities are present
|
||||
required_caps := ['CAP_AUDIT_WRITE', 'CAP_KILL', 'CAP_NET_BIND_SERVICE']
|
||||
for cap in required_caps {
|
||||
@@ -37,4 +37,4 @@ pub fn (config CrunConfig) validate() ! {
|
||||
return error('missing required capability: ${cap}')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user