diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3e9a76d..5e8431b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -21,8 +21,14 @@ jobs: with: go-version: 1.19 - - name: Build - run: go build -v ./... + - name: Build linux + run: GOOS=linux go build -v ./... + + - name: Build windows + run: GOOS=windows go build -v ./... + + - name: Build macos + run: GOOS=darwin go build -v ./... - name: Test run: go test -v ./... diff --git a/go.sum b/go.sum index 37e5084..3292f98 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,25 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/edwarnicke/gitoid v0.0.0-20220710194850-1be5bfda1f9d h1:4l+Uq5zFWSagXgGFaKRRVWJrnlzeathyagWgYUltCgY= github.com/edwarnicke/gitoid v0.0.0-20220710194850-1be5bfda1f9d/go.mod h1:WxWwA3EYuCQjlR5EBUX3uaTS8bh9BOa7BcqVREHQ0uQ= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/omnibor/omnibor-go v0.0.0-20230521145532-a77de61a16cd h1:25EpGVgctk6V3DUa1gqFHvjVbmdWqM+jBZAed7p/krQ= github.com/omnibor/omnibor-go v0.0.0-20230521145532-a77de61a16cd/go.mod h1:ArlQivzDQvZnFe8itjlA3ndPTXd9iWOgqzF31OyIEFQ= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -18,7 +28,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/omnitrail.go b/omnitrail.go index 2928dff..1534037 100644 --- a/omnitrail.go +++ b/omnitrail.go @@ -5,6 +5,14 @@ import ( "sort" ) +type PluginInit func() Plugin + +var pluginMap = make(map[string]PluginInit) + +func RegisterPlugin(name string, initFn PluginInit) { + pluginMap[name] = initFn +} + func NewTrail(option ...Option) Factory { o := &Options{} for _, opt := range option { @@ -15,9 +23,16 @@ func NewTrail(option ...Option) Factory { } allowList := []string{} plugins := make([]Plugin, 0) + // Directory plugin depends on the File plugin + // We assume all other plugins depend on both the File and Directory plugins plugins = append(plugins, NewFilePlugin()) plugins = append(plugins, NewDirectoryPlugin()) - plugins = append(plugins, NewPosixPlugin()) + // We load all other plugins here + for _, pluginInitFunc := range pluginMap { + plugins = append(plugins, pluginInitFunc()) + } + + fmt.Println(plugins) factory := &factoryImpl{ Options: o, diff --git a/omnitrail_test.go b/omnitrail_test.go index b1ca2cb..3398221 100644 --- a/omnitrail_test.go +++ b/omnitrail_test.go @@ -85,6 +85,9 @@ func testAdd(t *testing.T, name string) error { return err } + a, _ := json.MarshalIndent(mapping.Envelope(), "", " ") + fmt.Println(string(a)) + // WARNING: these are only for generating new test cases easily // file, err := json.MarshalIndent(mapping.Envelope(), "", " ") // os.WriteFile("./test/"+name+".json", file, 0644) @@ -106,8 +109,13 @@ func testAdd(t *testing.T, name string) error { shortestExpectedKey := getShortestKey(&expectedEnvelope) shortestActualKey := getShortestKey(mapping.Envelope()) + fmt.Println(shortestExpectedKey) + fmt.Println(shortestActualKey) + for oldKey, val := range expectedEnvelope.Mapping { + fmt.Println("old key: ", oldKey) newKey := strings.Replace(oldKey, shortestExpectedKey, shortestActualKey, 1) + fmt.Println("new key: ", oldKey) delete(expectedEnvelope.Mapping, oldKey) expectedEnvelope.Mapping[newKey] = val } diff --git a/posix_plugin_unix.go b/posix_plugin_unix.go index cf37cdd..d55ad6b 100644 --- a/posix_plugin_unix.go +++ b/posix_plugin_unix.go @@ -1,3 +1,5 @@ +//go:build linux || darwin + package omnitrail import ( @@ -9,6 +11,10 @@ import ( "syscall" ) +func init() { + RegisterPlugin("posix", NewPosixPlugin) +} + type PosixPlugin struct { params map[string]*posixInfo AllowList []string