1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

Add tests.

Signed-off-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Felix Fontein
2025-08-30 16:59:40 +02:00
parent d67d29fd96
commit 2e2d7d998c
2 changed files with 67 additions and 0 deletions

View File

@@ -265,6 +265,57 @@ bar: baz
}
}
#[test]
fn test_ini_values_as_strings() {
let file_path = prepare_temp_file(
"test_ini_values_as_strings.yaml",
b"the_section:
int: 123
float: 1.23
bool: true
date: 2025-01-02
timestamp: 2025-01-02 03:04:05
utc_timestamp: 2025-01-02T03:04:05Z
string: this is a string",
);
assert!(
Command::new(SOPS_BINARY_PATH)
.arg("encrypt")
.arg("-i")
.arg(file_path.clone())
.output()
.expect("Error running sops")
.status
.success(),
"sops didn't exit successfully"
);
let output = Command::new(SOPS_BINARY_PATH)
.arg("decrypt")
.arg("--output-type")
.arg("ini")
.arg(file_path.clone())
.output()
.expect("Error running sops");
println!(
"stdout: {}, stderr: {}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
assert!(output.status.success(), "sops didn't exit successfully");
let data = &String::from_utf8_lossy(&output.stdout);
assert!(
data == "[the_section]
int = 123
float = 1.230000
bool = true
date = 2025-01-02T00:00:00Z
timestamp = 2025-01-02T03:04:05Z
utc_timestamp = 2025-01-02T03:04:05Z
string = this is a string
"
);
}
#[test]
fn encrypt_yaml_file() {
let file_path = prepare_temp_file(

View File

@@ -2,6 +2,7 @@ package ini
import (
"testing"
"time"
"github.com/getsops/sops/v3"
"github.com/stretchr/testify/assert"
@@ -182,3 +183,18 @@ func TestUnmarshalMetadataFromNonSOPSFile(t *testing.T) {
_, err := store.LoadEncryptedFile(data)
assert.Equal(t, sops.MetadataNotFound, err)
}
func TestValToString(t *testing.T) {
store := Store{}
assert.Equal(t, "1", store.valToString(1))
assert.Equal(t, "1.000000", store.valToString(1.0))
assert.Equal(t, "-20000000000.000000", store.valToString(-2e10))
assert.Equal(t, "0.000000", store.valToString(2e-10))
assert.Equal(t, "12345000000000000583883634749019137936624068583482471750845213260941541453980911162485633595979333632.000000", store.valToString(1.2345e100))
assert.Equal(t, "0.000000", store.valToString(1.2345e-100))
assert.Equal(t, "true", store.valToString(true))
assert.Equal(t, "false", store.valToString(false))
ts, _ := time.Parse(time.RFC3339, "2025-01-02T03:04:05Z")
assert.Equal(t, "2025-01-02T03:04:05Z", store.valToString(ts))
assert.Equal(t, "a string", store.valToString("a string"))
}