Skip to content

Commit

Permalink
fix(ci): build linux/macos specific test not on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
phwissmann authored and consolethinks committed Dec 16, 2024
1 parent 7dcbe9b commit 52c04ea
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 70 deletions.
82 changes: 82 additions & 0 deletions internal/metadataextractor/extractor_linux_macos_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
70 changes: 0 additions & 70 deletions internal/metadataextractor/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (
"os"
"path"
"reflect"
"runtime"
"testing"
"time"
)

func TestNewExtractorHandler(t *testing.T) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 52c04ea

Please sign in to comment.