Просмотр исходного кода

staticpath tests

Signed-off-by: Sean Holcomb <seanholcomb@gmail.com>
Sean Holcomb 1 месяц назад
Родитель
Сommit
be89b58106
1 измененных файлов с 73 добавлено и 0 удалено
  1. 73 0
      core/pkg/exporter/pathing/staticpath_test.go

+ 73 - 0
core/pkg/exporter/pathing/staticpath_test.go

@@ -6,6 +6,52 @@ import (
 	"github.com/stretchr/testify/require"
 )
 
+func TestNewStaticFileStoragePathFormatter(t *testing.T) {
+	tests := []struct {
+		name     string
+		rootDir  string
+		pipeline string
+		wantErr  bool
+	}{
+		{"empty rootDir returns error", "", "pricingmodel", true},
+		{"empty pipeline returns error", "cloud-agent", "", true},
+		{"valid args returns formatter", "cloud-agent", "pricingmodel", false},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			f, err := NewStaticFileStoragePathFormatter(tt.rootDir, tt.pipeline)
+			if tt.wantErr {
+				require.Error(t, err)
+				require.Nil(t, f)
+			} else {
+				require.NoError(t, err)
+				require.NotNil(t, f)
+			}
+		})
+	}
+}
+
+func TestStaticFileStoragePathFormatter_Dir(t *testing.T) {
+	tests := []struct {
+		rootDir  string
+		pipeline string
+		expected string
+	}{
+		{"cloud-agent", "pricingmodel", "cloud-agent/pricingmodel"},
+		{"/var/data", "kubemodel", "/var/data/kubemodel"},
+		{"root", "a/b/c", "root/a/b/c"},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.expected, func(t *testing.T) {
+			f, err := NewStaticFileStoragePathFormatter(tt.rootDir, tt.pipeline)
+			require.NoError(t, err)
+			require.Equal(t, tt.expected, f.Dir())
+		})
+	}
+}
+
 func TestStaticFilePathFormatter(t *testing.T) {
 	type testCase struct {
 		name     string
@@ -54,6 +100,33 @@ func TestStaticFilePathFormatter(t *testing.T) {
 			fileExt:  "",
 			expected: "cloud-agent/pricingmodel/v1.aws_list_pricing_api",
 		},
+		{
+			name:     "in with subdir no prefix no ext",
+			rootDir:  "cloud-agent",
+			pipeline: "pricingmodel",
+			prefix:   "",
+			in:       "us-east-1/aws_list_pricing_api",
+			fileExt:  "",
+			expected: "cloud-agent/pricingmodel/us-east-1/aws_list_pricing_api",
+		},
+		{
+			name:     "in with subdir with prefix and ext",
+			rootDir:  "cloud-agent",
+			pipeline: "pricingmodel",
+			prefix:   "v1",
+			in:       "us-east-1/aws_list_pricing_api",
+			fileExt:  "bin",
+			expected: "cloud-agent/pricingmodel/us-east-1/v1.aws_list_pricing_api.bin",
+		},
+		{
+			name:     "in with nested subdir with ext",
+			rootDir:  "/var/data",
+			pipeline: "kubemodel",
+			prefix:   "",
+			in:       "2024/01/nodes",
+			fileExt:  "bin",
+			expected: "/var/data/kubemodel/2024/01/nodes.bin",
+		},
 	}
 
 	for _, tc := range testCases {