From 52c04ea7b8d913be535e773bea4d84fbf607b7a4 Mon Sep 17 00:00:00 2001 From: Philipp Wissmann Date: Mon, 16 Dec 2024 14:21:26 +0100 Subject: [PATCH] fix(ci): build linux/macos specific test not on Windows --- .../extractor_linux_macos_test.go | 82 +++++++++++++++++++ internal/metadataextractor/extractor_test.go | 70 ---------------- 2 files changed, 82 insertions(+), 70 deletions(-) create mode 100644 internal/metadataextractor/extractor_linux_macos_test.go diff --git a/internal/metadataextractor/extractor_linux_macos_test.go b/internal/metadataextractor/extractor_linux_macos_test.go new file mode 100644 index 0000000..72dfcb9 --- /dev/null +++ b/internal/metadataextractor/extractor_linux_macos_test.go @@ -0,0 +1,82 @@ +//go:build !windows +// +build !windows + +package metadataextractor + +import ( + "context" + "html/template" + "os" + "path" + "runtime" + "testing" + "time" +) + +func TestExtractorHandler_ExtractMetadata(t *testing.T) { + // TODO: make platform independent + templ, _ := template.New("name").Parse("{} {{.OutputFile}}") + _, goFile, _, ok := runtime.Caller(0) + if !ok { + return // skip test if can't get path + } + currDir := path.Dir(goFile) + execPath := path.Join(currDir, "extractor_test_echoToFile.sh") + + type fields struct { + methods map[string]Method + extractors map[string]Extractor + outputFolder string + } + type args struct { + extractor_name string + folder string + output_file string + } + tests := []struct { + name string + fields fields + args args + want string + wantErr bool + }{ + { + name: "echoExtractor", + fields: fields{ + methods: map[string]Method{"echoExtractor": {Name: "echoExtractor", Schema: "someschema", Extractor: "echoExtractor"}}, + extractors: map[string]Extractor{ + "echoExtractor": { + ExecutablePath: execPath, + templ: templ, + }, + }, + }, + args: args{ + extractor_name: "echoExtractor", + folder: "./", + output_file: path.Join(os.TempDir(), "output.txt"), + }, + want: "{}\n", // size of a directory on linux + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + e := &ExtractorHandler{ + methods: tt.fields.methods, + extractors: tt.fields.extractors, + outputFolder: tt.fields.outputFolder, + timeout: time.Minute, + } + ctx := context.Background() + got, err := e.ExtractMetadata(ctx, tt.args.extractor_name, tt.args.folder, tt.args.output_file, stdout_callback, stderr_callback) + if (err != nil) != tt.wantErr { + t.Errorf("ExtractorHandler.ExtractMetadata() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("ExtractorHandler.ExtractMetadata() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/metadataextractor/extractor_test.go b/internal/metadataextractor/extractor_test.go index 4e3ceda..0976fc9 100644 --- a/internal/metadataextractor/extractor_test.go +++ b/internal/metadataextractor/extractor_test.go @@ -8,9 +8,7 @@ import ( "os" "path" "reflect" - "runtime" "testing" - "time" ) func TestNewExtractorHandler(t *testing.T) { @@ -309,74 +307,6 @@ func Test_runExtractor(t *testing.T) { } } -func TestExtractorHandler_ExtractMetadata(t *testing.T) { - // TODO: make platform independent - templ, _ := template.New("name").Parse("{} {{.OutputFile}}") - _, goFile, _, ok := runtime.Caller(0) - if !ok { - return // skip test if can't get path - } - currDir := path.Dir(goFile) - execPath := path.Join(currDir, "extractor_test_echoToFile.sh") - - type fields struct { - methods map[string]Method - extractors map[string]Extractor - outputFolder string - } - type args struct { - extractor_name string - folder string - output_file string - } - tests := []struct { - name string - fields fields - args args - want string - wantErr bool - }{ - { - name: "echoExtractor", - fields: fields{ - methods: map[string]Method{"echoExtractor": {Name: "echoExtractor", Schema: "someschema", Extractor: "echoExtractor"}}, - extractors: map[string]Extractor{ - "echoExtractor": { - ExecutablePath: execPath, - templ: templ, - }, - }, - }, - args: args{ - extractor_name: "echoExtractor", - folder: "./", - output_file: path.Join(os.TempDir(), "output.txt"), - }, - want: "{}\n", // size of a directory on linux - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := &ExtractorHandler{ - methods: tt.fields.methods, - extractors: tt.fields.extractors, - outputFolder: tt.fields.outputFolder, - timeout: time.Minute, - } - ctx := context.Background() - got, err := e.ExtractMetadata(ctx, tt.args.extractor_name, tt.args.folder, tt.args.output_file, stdout_callback, stderr_callback) - if (err != nil) != tt.wantErr { - t.Errorf("ExtractorHandler.ExtractMetadata() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("ExtractorHandler.ExtractMetadata() = %v, want %v", got, tt.want) - } - }) - } -} - func TestSplitString(t *testing.T) { type args struct { str string