From dd47b9c3a9b1fd21240c159ca33b0c2a8f5e9880 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Mon, 9 Feb 2026 14:46:40 +0000 Subject: [PATCH] feat(e2e-tests): add CRUD and idempotency tests for oneuptime_file resource --- .../e2e-tests/tests/38-file-crud/main.tf | 72 +++++++++++++++ .../e2e-tests/tests/38-file-crud/variables.tf | 10 +++ .../e2e-tests/tests/38-file-crud/verify.sh | 88 +++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 E2E/Terraform/e2e-tests/tests/38-file-crud/main.tf create mode 100644 E2E/Terraform/e2e-tests/tests/38-file-crud/variables.tf create mode 100755 E2E/Terraform/e2e-tests/tests/38-file-crud/verify.sh diff --git a/E2E/Terraform/e2e-tests/tests/38-file-crud/main.tf b/E2E/Terraform/e2e-tests/tests/38-file-crud/main.tf new file mode 100644 index 0000000000..c494366ff6 --- /dev/null +++ b/E2E/Terraform/e2e-tests/tests/38-file-crud/main.tf @@ -0,0 +1,72 @@ +terraform { + required_providers { + oneuptime = { + source = "oneuptime/oneuptime" + version = "1.0.0" + } + } +} + +provider "oneuptime" { + oneuptime_url = var.oneuptime_url + api_key = var.api_key +} + +# Test for oneuptime_file resource CRUD and idempotency +# This test validates that: +# 1. File resource can be created with base64 content +# 2. A second terraform plan succeeds without "Read Not Implemented" error +# 3. The resource state is preserved correctly across plan/apply cycles +# +# Bug scenario being tested: +# - First apply: CREATE succeeds, file is uploaded +# - Second plan: READ was returning "Read Not Implemented" error +# - Fix: READ now preserves existing state as a no-op +resource "oneuptime_file" "logo" { + name = "tf-e2e-logo-${formatdate("YYYYMMDDhhmmss", timestamp())}" + file_type = "image/png" + # Small 1x1 red PNG pixel encoded as base64 + file = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==" + is_public = "true" + + lifecycle { + ignore_changes = [name] + } +} + +resource "oneuptime_file" "favicon" { + name = "tf-e2e-favicon-${formatdate("YYYYMMDDhhmmss", timestamp())}" + file_type = "image/png" + # Same small 1x1 PNG pixel + file = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==" + is_public = "true" + + lifecycle { + ignore_changes = [name] + } +} + +output "logo_id" { + value = oneuptime_file.logo.id + description = "ID of the created logo file" +} + +output "logo_name" { + value = oneuptime_file.logo.name + description = "Name of the created logo file" +} + +output "logo_file_type" { + value = oneuptime_file.logo.file_type + description = "File type of the created logo file" +} + +output "favicon_id" { + value = oneuptime_file.favicon.id + description = "ID of the created favicon file" +} + +output "favicon_name" { + value = oneuptime_file.favicon.name + description = "Name of the created favicon file" +} diff --git a/E2E/Terraform/e2e-tests/tests/38-file-crud/variables.tf b/E2E/Terraform/e2e-tests/tests/38-file-crud/variables.tf new file mode 100644 index 0000000000..e66c932ad9 --- /dev/null +++ b/E2E/Terraform/e2e-tests/tests/38-file-crud/variables.tf @@ -0,0 +1,10 @@ +variable "oneuptime_url" { + type = string + description = "OneUptime API URL" +} + +variable "api_key" { + type = string + description = "OneUptime API Key" + sensitive = true +} diff --git a/E2E/Terraform/e2e-tests/tests/38-file-crud/verify.sh b/E2E/Terraform/e2e-tests/tests/38-file-crud/verify.sh new file mode 100755 index 0000000000..70b2ea1e09 --- /dev/null +++ b/E2E/Terraform/e2e-tests/tests/38-file-crud/verify.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# Verify script for 38-file-crud test +# +# This test validates the oneuptime_file resource: +# 1. File resources are created successfully +# 2. A second terraform plan does NOT fail with "Read Not Implemented" +# 3. The state is preserved correctly (idempotency) +# +# This is the critical regression test for: +# https://github.com/OneUptime/oneuptime/issues/XXXX +# "Error: Read Not Implemented - This resource does not support read operations" + +set -e + +# Source common library +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/../../scripts/lib.sh" + +print_header "File Resource CRUD & Idempotency Verification" + +# Get terraform outputs +LOGO_ID=$(get_output logo_id) +FAVICON_ID=$(get_output favicon_id) +LOGO_NAME=$(get_output logo_name) +FAVICON_NAME=$(get_output favicon_name) +LOGO_FILE_TYPE=$(get_output logo_file_type) + +echo " Logo ID: $LOGO_ID" +echo " Favicon ID: $FAVICON_ID" + +# Step 1: Validate that resource IDs were created +validation_failed=0 + +assert_not_empty "$LOGO_ID" "Logo ID" || validation_failed=1 +assert_not_empty "$FAVICON_ID" "Favicon ID" || validation_failed=1 +assert_not_empty "$LOGO_NAME" "Logo Name" || validation_failed=1 +assert_not_empty "$FAVICON_NAME" "Favicon Name" || validation_failed=1 + +if [ $validation_failed -eq 1 ]; then + print_failed "File Resource Creation" +fi + +echo "" +echo " === Step 1: File resources created successfully ===" + +# Step 2: Verify file_type is preserved in state +assert_equals "image/png" "$LOGO_FILE_TYPE" "Logo file_type" || validation_failed=1 + +if [ $validation_failed -eq 1 ]; then + print_failed "File Resource Field Verification" +fi + +echo "" +echo " === Step 2: File resource fields verified ===" + +# Step 3: Critical test - Run terraform plan to check for "Read Not Implemented" error +# This is the exact bug that was reported: second plan fails with Read Not Implemented +echo "" +echo " === Step 3: Verifying second plan succeeds (no Read Not Implemented error) ===" +echo " Running terraform plan to check for errors..." + +PLAN_OUTPUT=$(terraform plan -detailed-exitcode 2>&1) || PLAN_EXIT_CODE=$? +PLAN_EXIT_CODE=${PLAN_EXIT_CODE:-0} + +if [ "$PLAN_EXIT_CODE" -eq 1 ]; then + # Check specifically for the "Read Not Implemented" error + if echo "$PLAN_OUTPUT" | grep -q "Read Not Implemented"; then + echo " ✗ FAILED: 'Read Not Implemented' error on second plan!" + echo " This is the exact bug being tested." + echo " Plan output:" + echo "$PLAN_OUTPUT" + print_failed "File Resource Read Idempotency" + fi + echo " ✗ FAILED: terraform plan error (exit code 1)" + echo "$PLAN_OUTPUT" + print_failed "File Resource Plan" +elif [ "$PLAN_EXIT_CODE" -eq 0 ]; then + echo " ✓ Terraform plan shows no changes - idempotency PASSED" +elif [ "$PLAN_EXIT_CODE" -eq 2 ]; then + # Changes detected but no error - acceptable for timestamp-based names + echo " ⚠ Changes detected (expected due to timestamp in name with lifecycle ignore)" + echo " ✓ No 'Read Not Implemented' error - the critical fix is working" +fi + +echo "" +echo " === Step 3: Second plan succeeded (no Read Not Implemented error) ===" + +print_passed "File Resource CRUD & Idempotency Verification"