From 474100c1f1caf7583142fe8c2a6887d3b3014ee4 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Mon, 23 Aug 2021 19:53:37 +0530 Subject: [PATCH] rbd: add a unit test for getCephClientLogFileName() Signed-off-by: Prasanna Kumar Kalever --- internal/rbd/rbd_util_test.go | 71 +++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/internal/rbd/rbd_util_test.go b/internal/rbd/rbd_util_test.go index 1dfa35d7d..2a44682db 100644 --- a/internal/rbd/rbd_util_test.go +++ b/internal/rbd/rbd_util_test.go @@ -189,3 +189,74 @@ func TestGetMappedID(t *testing.T) { }) } } + +func TestGetCephClientLogFileName(t *testing.T) { + t.Parallel() + type args struct { + id string + logDir string + prefix string + } + volID := "0001-0024-fed5480a-f00f-417a-a51d-31d8a8144c03-0000000000000003-eba90b33-0156-11ec-a30b-4678a93686c2" + tests := []struct { + name string + args args + expected string + }{ + { + name: "test for empty id", + args: args{ + id: "", + logDir: "/var/log/ceph-csi", + prefix: "rbd-nbd", + }, + expected: "/var/log/ceph-csi/rbd-nbd-.log", + }, + { + name: "test for empty logDir", + args: args{ + id: volID, + logDir: "", + prefix: "rbd-nbd", + }, + expected: "/var/log/ceph/rbd-nbd-" + volID + ".log", + }, + { + name: "test for empty prefix", + args: args{ + id: volID, + logDir: "/var/log/ceph-csi", + prefix: "", + }, + expected: "/var/log/ceph-csi/ceph-" + volID + ".log", + }, + { + name: "test for all unavailable args", + args: args{ + id: "", + logDir: "", + prefix: "", + }, + expected: "/var/log/ceph/ceph-.log", + }, + { + name: "test for all available args", + args: args{ + id: volID, + logDir: "/var/log/ceph-csi", + prefix: "rbd-nbd", + }, + expected: "/var/log/ceph-csi/rbd-nbd-" + volID + ".log", + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + val := getCephClientLogFileName(tt.args.id, tt.args.logDir, tt.args.prefix) + if val != tt.expected { + t.Errorf("getCephClientLogFileName() got = %v, expected %v", val, tt.expected) + } + }) + } +}