Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resolver = "2"
name = "cloudformation-validate"

[workspace.package]
version = "1.10.0"
version = "1.9.0"
edition = "2024"
license = "Apache-2.0"
description = "AWS CloudFormation Validate"
Expand Down
16 changes: 8 additions & 8 deletions src/bindings-go/tests/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -94,16 +93,17 @@ func diagnosticKeys(report *cfnvalidate.StandardReport) []string {
return keys
}

func TestVersionMatchesWorkspaceCargoToml(t *testing.T) {
content, err := os.ReadFile(filepath.Join(workspaceDir, "Cargo.toml"))
func TestVersionMatchesExpectedVersionFixture(t *testing.T) {
expectedVersionPath := filepath.Join(workspaceDir, "resources", "expected", "version.txt")
content, err := os.ReadFile(expectedVersionPath)
if err != nil {
t.Fatalf("reading workspace Cargo.toml: %v", err)
t.Fatalf("reading expected version fixture: %v", err)
}
match := regexp.MustCompile(`(?s)\[workspace\.package\].*?version = "([^"]+)"`).FindSubmatch(content)
if match == nil {
t.Fatal("missing version under [workspace.package] in workspace Cargo.toml")
expectedVersion := strings.TrimSpace(string(content))
if expectedVersion == "" {
t.Fatalf("%s must not be empty", expectedVersionPath)
}
if got, want := cfnvalidate.Version(), string(match[1]); got != want {
if got, want := cfnvalidate.Version(), expectedVersion; got != want {
t.Errorf("Version() = %q, want %q", got, want)
}
}
Expand Down
30 changes: 7 additions & 23 deletions src/bindings-jvm/tests/kotlin/src/test/kotlin/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,16 @@ class SmokeTest {

// ── version ──────────────────────────────────────────────────────────────

private fun readWorkspaceVersion(): String {
val cargoToml = File(resourcesRoot.parentFile, "Cargo.toml")
var inWorkspacePackage = false
for (line in cargoToml.readLines()) {
val trimmed = line.trim()
if (trimmed == "[workspace.package]") {
inWorkspacePackage = true
continue
}
if (inWorkspacePackage && trimmed.startsWith("[")) {
break
}
if (inWorkspacePackage && trimmed.startsWith("version = ")) {
val value = trimmed.removePrefix("version = ").trim()
require(value.startsWith("\"") && value.endsWith("\"")) {
"malformed version line in ${cargoToml.path}: $line"
}
return value.substring(1, value.length - 1)
}
}
error("missing 'version = ' under [workspace.package] in ${cargoToml.path}")
private fun readExpectedVersion(): String {
val expectedVersionFile = File(expectedDir, "version.txt")
val expectedVersion = expectedVersionFile.readText().trim()
require(expectedVersion.isNotEmpty()) { "${expectedVersionFile.path} must not be empty" }
return expectedVersion
}

@Test
fun versionReturnsCrateVersionFromWorkspaceCargoToml() {
assertEquals(readWorkspaceVersion(), version())
fun versionReturnsExpectedVersionFixture() {
assertEquals(readExpectedVersion(), version())
}

// ── Engine construction ──────────────────────────────────────────────────
Expand Down
29 changes: 9 additions & 20 deletions src/bindings-python/tests/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

import os
import re
import tempfile
import unittest
from unittest import mock
Expand Down Expand Up @@ -68,23 +67,13 @@
}"""


def read_workspace_version():
cargo_toml = os.path.join(WORKSPACE, "Cargo.toml")
in_workspace_package = False
with open(cargo_toml, encoding="utf-8") as f:
for line in f:
stripped = line.strip()
if stripped == "[workspace.package]":
in_workspace_package = True
continue
if in_workspace_package and stripped.startswith("["):
break
if in_workspace_package and stripped.startswith("version = "):
match = re.fullmatch(r'version = "([^"]+)"', stripped)
if not match:
raise AssertionError(f"malformed version line in {cargo_toml}: {line}")
return match.group(1)
raise AssertionError(f"missing 'version = ' under [workspace.package] in {cargo_toml}")
def read_expected_version():
expected_version_path = os.path.join(RESOURCES, "expected", "version.txt")
with open(expected_version_path, encoding="utf-8") as f:
expected_version = f.read().strip()
if not expected_version:
raise AssertionError(f"{expected_version_path} must not be empty")
return expected_version


def load_rule(filename):
Expand All @@ -102,8 +91,8 @@ def diagnostic_keys(report):


class VersionTest(unittest.TestCase):
def test_version_matches_workspace_cargo_toml(self):
self.assertEqual(read_workspace_version(), version())
def test_version_matches_expected_version_fixture(self):
self.assertEqual(read_expected_version(), version())


class EngineConstructionTest(unittest.TestCase):
Expand Down
31 changes: 8 additions & 23 deletions src/bindings-wasm/tests/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,18 @@ function stripSnapshotExcludedFields(report: any, filePath?: string): unknown {

// ── version ──────────────────────────────────────────────────────────────────

function readWorkspaceVersion(): string {
const cargoTomlPath = path.resolve(__dirname, '../../Cargo.toml');
const lines = fs.readFileSync(cargoTomlPath, 'utf-8').split('\n');
let inWorkspacePackage = false;
for (const line of lines) {
const trimmed = line.trim();
if (trimmed === '[workspace.package]') {
inWorkspacePackage = true;
continue;
}
if (inWorkspacePackage && trimmed.startsWith('[')) {
break;
}
if (inWorkspacePackage && trimmed.startsWith('version = ')) {
const value = trimmed.slice('version = '.length).trim();
if (!value.startsWith('"') || !value.endsWith('"')) {
throw new Error(`malformed version line in ${cargoTomlPath}: ${line}`);
}
return value.slice(1, -1);
}
function readExpectedVersion(): string {
const expectedVersionPath = path.join(EXPECTED_DIR, 'version.txt');
const expectedVersion = fs.readFileSync(expectedVersionPath, 'utf-8').trim();
if (expectedVersion.length === 0) {
throw new Error(`${expectedVersionPath} must not be empty`);
}
throw new Error(`missing 'version = ' under [workspace.package] in ${cargoTomlPath}`);
return expectedVersion;
}

describe('version', () => {
it('returns the crate version from workspace Cargo.toml', () => {
expect(version()).toBe(readWorkspaceVersion());
it('returns the expected version fixture', () => {
expect(version()).toBe(readExpectedVersion());
});
});

Expand Down
15 changes: 13 additions & 2 deletions src/cfn-validate/tests/snapshot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,13 @@ fn report_metadata_contains_embedded_source_versions_on_all_outcomes() {
}

#[test]
fn engine_version_matches_workspace_version() {
fn engine_version_matches_expected_version_fixture() {
let expected_version_path = resources::expected_dir().join("version.txt");
let expected_version_text = std::fs::read_to_string(&expected_version_path)
.unwrap_or_else(|error| panic!("read {}: {error}", expected_version_path.display()));
let expected_version = expected_version_text.trim();
assert!(!expected_version.is_empty(), "{} must not be empty", expected_version_path.display());

let rego = RegoEngine::new(EngineConfig::default()).expect("rego engine");
let cel = CelEngine::new(EngineConfig::default()).expect("cel engine");
let bytes = load_template("good/generic.yaml");
Expand All @@ -235,7 +241,12 @@ fn engine_version_matches_workspace_version() {
("rego", validate_to_json(&rego, &bytes, "good/generic.yaml", DetailLevel::Detailed)),
("cel", validate_to_json(&cel, &bytes, "good/generic.yaml", DetailLevel::Detailed)),
] {
assert_eq!(report["version"].as_str(), Some("1.10.0"), "{name}: version must be the workspace crate version");
assert_eq!(
report["version"].as_str(),
Some(expected_version),
"{name}: version must match {}",
expected_version_path.display()
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/resources/examples/generate_validation_reports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ENGINES: &[&str] = &["rego", "cel"];
const PARITY_IGNORED_FIELDS: &[&str] = &["performance", "benchmarkMetrics", "suppressed"];

/// Top-level fields compared across engines but not persisted to the snapshot chunks.
const OUTPUT_ONLY_TOP_LEVEL_FIELDS: &[&str] = &["performance"];
const OUTPUT_ONLY_TOP_LEVEL_FIELDS: &[&str] = &["performance", "version"];

/// `metadata` fields compared across engines but not persisted to the snapshot chunks because they describe
/// the current binary's rule and data-source bundle.
Expand Down
Loading
Loading