diff mbox series

[v2,14/14] unit: Add test cases with tags_filter provided

Message ID 20240403160557.2828145-14-denkenz@gmail.com (mailing list archive)
State Accepted
Commit 393b6cc3dcbeb40c1a5b2068d5d1abaa32050397
Headers show
Series [v2,01/14] simutil: Convert eons APIs to use ell | expand

Commit Message

Denis Kenzior April 3, 2024, 4:05 p.m. UTC
Replace the XYZ operator contexts with a set of two.  One tagged as
'lte' and one tagged as '5g'.  Add logic to the provision unit test to
support filter tags.
---
 unit/test-provision.c    | 37 +++++++++++++++++++++++++++++++------
 unit/test-provision.json | 10 +++++++++-
 2 files changed, 40 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/unit/test-provision.c b/unit/test-provision.c
index b80f4d80fa0e..d251f31b148c 100644
--- a/unit/test-provision.c
+++ b/unit/test-provision.c
@@ -57,6 +57,7 @@  struct provision_test {
 	const char *mcc;
 	const char *mnc;
 	const char *spn;
+	const char *tags;
 	int result;
 	size_t n_items;
 	const struct provision_db_entry *items;
@@ -114,7 +115,7 @@  static const struct provision_db_entry charlie_contexts[] = {
 	},
 };
 
-static const struct provision_db_entry xyz_contexts[] = {
+static const struct provision_db_entry xyz_lte_contexts[] = {
 	{
 		.type = OFONO_GPRS_CONTEXT_TYPE_INTERNET |
 			OFONO_GPRS_CONTEXT_TYPE_IA,
@@ -124,6 +125,16 @@  static const struct provision_db_entry xyz_contexts[] = {
 	}
 };
 
+static const struct provision_db_entry xyz_5g_contexts[] = {
+	{
+		.type = OFONO_GPRS_CONTEXT_TYPE_INTERNET |
+			OFONO_GPRS_CONTEXT_TYPE_IA,
+		.proto = OFONO_GPRS_PROTO_IPV4V6,
+		.apn = "xyz.5g",
+		.auth_method = OFONO_GPRS_AUTH_METHOD_CHAP,
+	}
+};
+
 /* Make sure mccmnc not in the database isn't found */
 static const struct provision_test unknown_mcc_mnc = {
 	.mcc = "994",
@@ -204,13 +215,25 @@  static const struct provision_test lookup_charlie = {
 };
 
 /* Successful lookup of XYZ (MVNO on Charlie) */
-static const struct provision_test lookup_xyz = {
+static const struct provision_test lookup_lte_xyz = {
+	.mcc = "999",
+	.mnc = "11",
+	.spn = "XYZ",
+	.tags = "lte,unused",
+	.result = 0,
+	.n_items = L_ARRAY_SIZE(xyz_lte_contexts),
+	.items = xyz_lte_contexts,
+};
+
+/* Successful lookup of XYZ (MVNO on Charlie) */
+static const struct provision_test lookup_5g_xyz = {
 	.mcc = "999",
 	.mnc = "11",
 	.spn = "XYZ",
+	.tags = "5g",
 	.result = 0,
-	.n_items = L_ARRAY_SIZE(xyz_contexts),
-	.items = xyz_contexts,
+	.n_items = L_ARRAY_SIZE(xyz_5g_contexts),
+	.items = xyz_5g_contexts,
 };
 
 /* No match with for an MCC/MNC present in the DB, but no wildcard entry */
@@ -224,11 +247,12 @@  static void provision_lookup(const void *data)
 {
 	const struct provision_test *test = data;
 	struct provision_db_entry *items;
+	_auto_(l_strv_free) char **tags = l_strsplit(test->tags, ',');
 	size_t n_items;
 	size_t i;
 	int r;
 
-	r = provision_db_lookup(pdb, test->mcc, test->mnc, test->spn, NULL,
+	r = provision_db_lookup(pdb, test->mcc, test->mnc, test->spn, tags,
 					&items, &n_items);
 	assert(r == test->result);
 
@@ -270,7 +294,8 @@  int main(int argc, char **argv)
 	l_test_add("Successful lookup (Alpha)", provision_lookup, &lookup_alpha);
 	l_test_add("Successful lookup (ZYX)", provision_lookup, &lookup_zyx);
 	l_test_add("Exact match (Charlie)", provision_lookup, &lookup_charlie);
-	l_test_add("Exact match (XYZ)", provision_lookup, &lookup_xyz);
+	l_test_add("Exact match (XYZ)", provision_lookup, &lookup_lte_xyz);
+	l_test_add("Exact match (XYZ 5G)", provision_lookup, &lookup_5g_xyz);
 	l_test_add("Exact math (no match)", provision_lookup, &lookup_no_match);
 
 	pdb = provision_db_new(UNITDIR "test-provision.db");
diff --git a/unit/test-provision.json b/unit/test-provision.json
index 61d060ad4def..fcf82a67bb67 100644
--- a/unit/test-provision.json
+++ b/unit/test-provision.json
@@ -85,7 +85,15 @@ 
         "apn": "xyz",
         "type": [
           "internet", "ia"
-        ]
+        ],
+	"tags": "lte"
+      },
+      {
+        "apn": "xyz.5g",
+        "type": [
+          "internet", "ia"
+        ],
+	"tags": "5g"
       }
     ]
   }