import json
import sys
from CacheLib import (
    ogCreateCache, ogDeleteCache, ogFindCache, ogFormatCache,
    ogGetCacheSize, ogGetCacheSpace, ogMountCache, ogUnmountCache,
    ogRaiseError
)

def load_test_data(file_path):
    with open(file_path, 'r') as file:
        return json.load(file)

def test_ogCreateCache(test_cases):
    for case in test_cases:
        try:
            ogCreateCache(**case)
            print(f"ogCreateCache({case}) pasó la prueba")
        except Exception as e:
            print(f"ogCreateCache({case}) falló la prueba: {e}")

def test_ogDeleteCache(test_cases):
    for case in test_cases:
        try:
            ogDeleteCache()
            print(f"ogDeleteCache() pasó la prueba")
        except Exception as e:
            print(f"ogDeleteCache() falló la prueba: {e}")

def test_ogFindCache(test_cases):
    for case in test_cases:
        try:
            result = ogFindCache()
            print(f"ogFindCache() pasó la prueba, resultado: {result}")
        except Exception as e:
            print(f"ogFindCache() falló la prueba: {e}")

def test_ogFormatCache(test_cases):
    for case in test_cases:
        try:
            ogFormatCache()
            print(f"ogFormatCache() pasó la prueba")
        except Exception as e:
            print(f"ogFormatCache() falló la prueba: {e}")

def test_ogGetCacheSize(test_cases):
    for case in test_cases:
        try:
            result = ogGetCacheSize()
            print(f"ogGetCacheSize() pasó la prueba, tamaño: {result} KB")
        except Exception as e:
            print(f"ogGetCacheSize() falló la prueba: {e}")

def test_ogGetCacheSpace(test_cases):
    for case in test_cases:
        try:
            result = ogGetCacheSpace()
            print(f"ogGetCacheSpace() pasó la prueba, espacio libre: {result} KB")
        except Exception as e:
            print(f"ogGetCacheSpace() falló la prueba: {e}")

def test_ogMountCache(test_cases):
    for case in test_cases:
        try:
            ogMountCache(**case)
            print(f"ogMountCache({case}) pasó la prueba")
        except Exception as e:
            print(f"ogMountCache({case}) falló la prueba: {e}")

def test_ogUnmountCache(test_cases):
    for case in test_cases:
        try:
            ogUnmountCache()
            print(f"ogUnmountCache() pasó la prueba")
        except Exception as e:
            print(f"ogUnmountCache() falló la prueba: {e}")

def run_tests(test_data):
    test_ogCreateCache(test_data.get("ogCreateCache", []))
    test_ogDeleteCache(test_data.get("ogDeleteCache", []))
    test_ogFindCache(test_data.get("ogFindCache", []))
    test_ogFormatCache(test_data.get("ogFormatCache", []))
    test_ogGetCacheSize(test_data.get("ogGetCacheSize", []))
    test_ogGetCacheSpace(test_data.get("ogGetCacheSpace", []))
    test_ogMountCache(test_data.get("ogMountCache", []))
    test_ogUnmountCache(test_data.get("ogUnmountCache", []))

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Uso: python3 test_CacheLib.py <ruta_al_archivo_json>")
        sys.exit(1)

    test_data_file = sys.argv[1]
    test_data = load_test_data(test_data_file)
    run_tests(test_data)

