#!/bin/sh

# Read test data
VARIANT=$(cat test-data/greengrass-variant)
COMPONENT_NAME=$(cat test-data/component-name)
COMPONENT_VERSION=$(cat test-data/component-version)
ARTIFACT=$(cat test-data/expected-artifact)

# Test 1: Check component recipe exists
if [ -f test-data/component-recipe.yaml ]; then
    echo "PASS: component-recipe.yaml exists"
else
    echo "FAIL: component-recipe.yaml not found"
fi

# Test 2: Verify component name in recipe
if grep -q "$COMPONENT_NAME" test-data/component-recipe.yaml; then
    echo "PASS: component name found in recipe"
else
    echo "FAIL: component name not found in recipe"
fi

# Test 3: Check artifact exists (for lite variant)
if [ "$VARIANT" = "lite" ]; then
    ARTIFACT_PATH="/var/lib/greengrass/packages/artifacts/$COMPONENT_NAME/$COMPONENT_VERSION/$ARTIFACT"
    if [ -f "$ARTIFACT_PATH" ]; then
        echo "PASS: artifact exists at $ARTIFACT_PATH"
    else
        echo "SKIP: artifact not found (may not be installed)"
    fi
fi

# Test 4: Verify artifact is executable
if [ "$VARIANT" = "lite" ]; then
    ARTIFACT_PATH="/var/lib/greengrass/packages/artifacts/$COMPONENT_NAME/$COMPONENT_VERSION/$ARTIFACT"
    if [ -x "$ARTIFACT_PATH" ]; then
        echo "PASS: artifact is executable"
    else
        echo "SKIP: artifact not executable or not found"
    fi
fi
