From c22a1c94ead27442b2e90b0a4fb0ef174fa8ad97 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 30 Jan 2026 13:29:04 -0600 Subject: [PATCH] test: add C NIF integration tests for web context Add lightweight integration tests to verify: - C NIF module loads properly in web application - MIB library initializes successfully - Standard MIB name resolution works - MibTranslator wrapper functions correctly - Error handling for invalid MIB names - SNMP profiles can be loaded (uses MIB translation) These tests verify the C NIF works end-to-end without checking full page content, focusing on functional verification only. --- .../integration/c_nif_integration_test.exs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/towerops_web/integration/c_nif_integration_test.exs diff --git a/test/towerops_web/integration/c_nif_integration_test.exs b/test/towerops_web/integration/c_nif_integration_test.exs new file mode 100644 index 00000000..51824e38 --- /dev/null +++ b/test/towerops_web/integration/c_nif_integration_test.exs @@ -0,0 +1,45 @@ +defmodule ToweropsWeb.Integration.CNifIntegrationTest do + @moduledoc """ + Integration tests to verify the C NIF is properly loaded and functional + in the web application context. + """ + use ToweropsWeb.ConnCase, async: true + + alias Towerops.Profiles.YamlProfiles + alias Towerops.Snmp.MibTranslator + + describe "C NIF initialization in web context" do + test "ToweropsNative module is loaded" do + assert Code.ensure_loaded?(ToweropsNative) + end + + test "MIB library is initialized" do + result = ToweropsNative.init_mib_library() + assert result in ["initialized", "already_initialized"] + end + + test "can resolve standard MIB names" do + assert "1.3.6.1.2.1.1.1" = ToweropsNative.resolve_oid("sysDescr") + assert "1.3.6.1.2.1.1.5" = ToweropsNative.resolve_oid("sysName") + end + + test "MibTranslator wrapper works" do + assert {:ok, "1.3.6.1.2.1.1.1.0"} = MibTranslator.translate("1.3.6.1.2.1.1.1.0") + assert {:ok, _oid} = MibTranslator.translate("sysDescr") + end + + test "handles invalid MIB names gracefully" do + assert {:error, _reason} = ToweropsNative.resolve_oid("nonExistentMibName") + assert {:error, :translation_failed} = MibTranslator.translate("INVALID-MIB::badObject") + end + end + + describe "SNMP operations with C NIF" do + test "profile matching can use MIB resolution" do + # Verify that SNMP profiles can be loaded (they use MIB translation) + profiles = YamlProfiles.list_profiles() + assert is_list(profiles) + assert profiles != [] + end + end +end