From b98c1fa7c95b2dc71784bfc94aa5da817965ce78 Mon Sep 17 00:00:00 2001 From: Jordi Martin Date: Thu, 22 Aug 2019 15:02:58 +0200 Subject: [PATCH] Expose vars pkg and some interfaces --- .gitignore | 2 ++ README.md | 2 +- cmd/mmock/main.go | 15 ++++++++------- internal/console/dispatcher.go | 7 ++++--- internal/{config => fs}/filesystem.go | 2 +- internal/{config => fs}/filesystem_test.go | 2 +- internal/{config => fs}/mapping.go | 9 +-------- internal/{config => fs}/mapping_test.go | 2 +- internal/{config => fs}/parser/json_reader.go | 0 .../{config => fs}/parser/json_reader_test.go | 0 internal/{config => fs}/parser/yaml_reader.go | 0 .../{config => fs}/parser/yaml_reader_test.go | 0 internal/{config => fs}/watcher.go | 2 +- internal/{config => fs}/watcher_test.go | 2 +- internal/server/dispatcher.go | 2 +- internal/server/router.go | 7 +++++-- pkg/config/mapping.go | 10 ++++++++++ {internal => pkg}/vars/evaluator.go | 0 {internal => pkg}/vars/evaluator_test.go | 0 {internal => pkg}/vars/fake.go | 2 +- {internal => pkg}/vars/fake/credit_card.go | 0 {internal => pkg}/vars/fake/generator.go | 0 {internal => pkg}/vars/fake/provider.go | 0 {internal => pkg}/vars/fake/provider_test.go | 0 {internal => pkg}/vars/filler.go | 2 +- {internal => pkg}/vars/request.go | 0 {internal => pkg}/vars/request_test.go | 0 {internal => pkg}/vars/stream.go | 0 {internal => pkg}/vars/stream_test.go | 0 29 files changed, 39 insertions(+), 29 deletions(-) rename internal/{config => fs}/filesystem.go (99%) rename internal/{config => fs}/filesystem_test.go (99%) rename internal/{config => fs}/mapping.go (95%) rename internal/{config => fs}/mapping_test.go (99%) rename internal/{config => fs}/parser/json_reader.go (100%) rename internal/{config => fs}/parser/json_reader_test.go (100%) rename internal/{config => fs}/parser/yaml_reader.go (100%) rename internal/{config => fs}/parser/yaml_reader_test.go (100%) rename internal/{config => fs}/watcher.go (98%) rename internal/{config => fs}/watcher_test.go (98%) create mode 100644 pkg/config/mapping.go rename {internal => pkg}/vars/evaluator.go (100%) rename {internal => pkg}/vars/evaluator_test.go (100%) rename {internal => pkg}/vars/fake.go (98%) rename {internal => pkg}/vars/fake/credit_card.go (100%) rename {internal => pkg}/vars/fake/generator.go (100%) rename {internal => pkg}/vars/fake/provider.go (100%) rename {internal => pkg}/vars/fake/provider_test.go (100%) rename {internal => pkg}/vars/filler.go (94%) rename {internal => pkg}/vars/request.go (100%) rename {internal => pkg}/vars/request_test.go (100%) rename {internal => pkg}/vars/stream.go (100%) rename {internal => pkg}/vars/stream_test.go (100%) diff --git a/.gitignore b/.gitignore index 2bc5d91..d1a41ad 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ data/* coverage.txt .github dist +.vscode +.idea diff --git a/README.md b/README.md index d52cb4d..a9bef34 100644 --- a/README.md +++ b/README.md @@ -244,7 +244,7 @@ You can extract information from the request body too, using a dot notation path - request.body."*key*" (support for `application/json`, `application/xml` and `application/x-www-form-urlencoded` requests) - request.body."*deep*"."*key*" (support for `application/json`, `application/xml` requests) -Quick overview of the path syntax available to extract values form the request: [https://github.com/tidwall/gjson#path-syntax] (https://github.com/tidwall/gjson#path-syntax) +Quick overview of the path syntax available to extract values form the request: [https://github.com/tidwall/gjson#path-syntax](https://github.com/tidwall/gjson#path-syntax) **External streams:** Perfect for embedding big payloads or getting data from another service. diff --git a/cmd/mmock/main.go b/cmd/mmock/main.go index 77295a5..3b19c61 100644 --- a/cmd/mmock/main.go +++ b/cmd/mmock/main.go @@ -10,16 +10,17 @@ import ( "path/filepath" "strings" - "github.com/jmartin82/mmock/internal/config" - "github.com/jmartin82/mmock/internal/config/parser" "github.com/jmartin82/mmock/internal/console" + "github.com/jmartin82/mmock/internal/fs" + "github.com/jmartin82/mmock/internal/fs/parser" "github.com/jmartin82/mmock/internal/server" "github.com/jmartin82/mmock/internal/statistics" - "github.com/jmartin82/mmock/internal/vars" - "github.com/jmartin82/mmock/internal/vars/fake" + "github.com/jmartin82/mmock/pkg/config" "github.com/jmartin82/mmock/pkg/match" "github.com/jmartin82/mmock/pkg/match/payload" "github.com/jmartin82/mmock/pkg/mock" + "github.com/jmartin82/mmock/pkg/vars" + "github.com/jmartin82/mmock/pkg/vars/fake" ) //VERSION of the application @@ -95,16 +96,16 @@ func getMapping(path string) config.Mapping { log.Fatalln(ErrNotFoundPath.Error()) } - fsMapper := config.NewFileSystemMapper() + fsMapper := fs.NewFileSystemMapper() fsMapper.AddParser(parser.JSONReader{}) fsMapper.AddParser(parser.YAMLReader{}) fsUpdate := make(chan struct{}) - watcher := config.NewFileWatcher(path, fsUpdate) + watcher := fs.NewFileWatcher(path, fsUpdate) watcher.Bind() - return config.NewConfigMapping(path, fsMapper, fsUpdate) + return fs.NewConfigMapping(path, fsMapper, fsUpdate) } func getRouter(mapping config.Mapping, checker match.Matcher) *server.Router { diff --git a/internal/console/dispatcher.go b/internal/console/dispatcher.go index 31bf276..e5277bc 100644 --- a/internal/console/dispatcher.go +++ b/internal/console/dispatcher.go @@ -3,7 +3,6 @@ package console import ( "errors" "fmt" - "github.com/jmartin82/mmock/internal/config" "log" "net/http" "regexp" @@ -12,9 +11,11 @@ import ( "strings" assetfs "github.com/elazarl/go-bindata-assetfs" - "github.com/jmartin82/mmock/pkg/mock" + "github.com/jmartin82/mmock/pkg/config" "github.com/jmartin82/mmock/pkg/match" - "github.com/jmartin82/mmock/internal/statistics" + "github.com/jmartin82/mmock/pkg/mock" + + "github.com/jmartin82/mmock/internal/statistics" "github.com/labstack/echo" "golang.org/x/net/websocket" ) diff --git a/internal/config/filesystem.go b/internal/fs/filesystem.go similarity index 99% rename from internal/config/filesystem.go rename to internal/fs/filesystem.go index 944e74c..9cb1722 100644 --- a/internal/config/filesystem.go +++ b/internal/fs/filesystem.go @@ -1,4 +1,4 @@ -package config +package fs import ( "encoding/json" diff --git a/internal/config/filesystem_test.go b/internal/fs/filesystem_test.go similarity index 99% rename from internal/config/filesystem_test.go rename to internal/fs/filesystem_test.go index 5667c75..0f01884 100644 --- a/internal/config/filesystem_test.go +++ b/internal/fs/filesystem_test.go @@ -1,4 +1,4 @@ -package config +package fs import ( "errors" diff --git a/internal/config/mapping.go b/internal/fs/mapping.go similarity index 95% rename from internal/config/mapping.go rename to internal/fs/mapping.go index 4ef77f9..824b7fb 100644 --- a/internal/config/mapping.go +++ b/internal/fs/mapping.go @@ -1,4 +1,4 @@ -package config +package fs import ( "errors" @@ -15,13 +15,6 @@ import ( var ErrFilePathIsNotUnderConfigPath = errors.New("File path is not under config path") var ErrMockDoesntExist = errors.New("Definition doesn't exist") -type Mapping interface { - Set(URI string, mock mock.Definition) error - Delete(URI string) error - Get(URI string) (mock.Definition, bool) - List() []mock.Definition -} - //PrioritySort mock array sorted by priority type PrioritySort []mock.Definition diff --git a/internal/config/mapping_test.go b/internal/fs/mapping_test.go similarity index 99% rename from internal/config/mapping_test.go rename to internal/fs/mapping_test.go index 0f821c9..2aea68d 100644 --- a/internal/config/mapping_test.go +++ b/internal/fs/mapping_test.go @@ -1,4 +1,4 @@ -package config +package fs import ( "github.com/jmartin82/mmock/pkg/mock" diff --git a/internal/config/parser/json_reader.go b/internal/fs/parser/json_reader.go similarity index 100% rename from internal/config/parser/json_reader.go rename to internal/fs/parser/json_reader.go diff --git a/internal/config/parser/json_reader_test.go b/internal/fs/parser/json_reader_test.go similarity index 100% rename from internal/config/parser/json_reader_test.go rename to internal/fs/parser/json_reader_test.go diff --git a/internal/config/parser/yaml_reader.go b/internal/fs/parser/yaml_reader.go similarity index 100% rename from internal/config/parser/yaml_reader.go rename to internal/fs/parser/yaml_reader.go diff --git a/internal/config/parser/yaml_reader_test.go b/internal/fs/parser/yaml_reader_test.go similarity index 100% rename from internal/config/parser/yaml_reader_test.go rename to internal/fs/parser/yaml_reader_test.go diff --git a/internal/config/watcher.go b/internal/fs/watcher.go similarity index 98% rename from internal/config/watcher.go rename to internal/fs/watcher.go index 59966a1..81bb71c 100644 --- a/internal/config/watcher.go +++ b/internal/fs/watcher.go @@ -1,4 +1,4 @@ -package config +package fs import ( "log" diff --git a/internal/config/watcher_test.go b/internal/fs/watcher_test.go similarity index 98% rename from internal/config/watcher_test.go rename to internal/fs/watcher_test.go index 9c98f1a..d295a28 100644 --- a/internal/config/watcher_test.go +++ b/internal/fs/watcher_test.go @@ -1,4 +1,4 @@ -package config +package fs import ( "io/ioutil" diff --git a/internal/server/dispatcher.go b/internal/server/dispatcher.go index 31d55fd..1f8c5a4 100644 --- a/internal/server/dispatcher.go +++ b/internal/server/dispatcher.go @@ -22,7 +22,7 @@ import ( "strings" "github.com/jmartin82/mmock/internal/statistics" - "github.com/jmartin82/mmock/internal/vars" + "github.com/jmartin82/mmock/pkg/vars" "github.com/jmartin82/mmock/pkg/mock" ) diff --git a/internal/server/router.go b/internal/server/router.go index 7482b1e..3c84e9e 100644 --- a/internal/server/router.go +++ b/internal/server/router.go @@ -3,10 +3,13 @@ package server import ( "bytes" "encoding/gob" - "github.com/jmartin82/mmock/internal/config" - "github.com/jmartin82/mmock/pkg/mock" + + "github.com/jmartin82/mmock/pkg/config" + "log" + "github.com/jmartin82/mmock/pkg/mock" + "github.com/jmartin82/mmock/pkg/match" ) diff --git a/pkg/config/mapping.go b/pkg/config/mapping.go new file mode 100644 index 0000000..6188c8a --- /dev/null +++ b/pkg/config/mapping.go @@ -0,0 +1,10 @@ +package config + +import "github.com/jmartin82/mmock/pkg/mock" + +type Mapping interface { + Set(URI string, mock mock.Definition) error + Delete(URI string) error + Get(URI string) (mock.Definition, bool) + List() []mock.Definition +} diff --git a/internal/vars/evaluator.go b/pkg/vars/evaluator.go similarity index 100% rename from internal/vars/evaluator.go rename to pkg/vars/evaluator.go diff --git a/internal/vars/evaluator_test.go b/pkg/vars/evaluator_test.go similarity index 100% rename from internal/vars/evaluator_test.go rename to pkg/vars/evaluator_test.go diff --git a/internal/vars/fake.go b/pkg/vars/fake.go similarity index 98% rename from internal/vars/fake.go rename to pkg/vars/fake.go index 4485101..b11035a 100644 --- a/internal/vars/fake.go +++ b/pkg/vars/fake.go @@ -2,7 +2,7 @@ package vars import ( "errors" - "github.com/jmartin82/mmock/internal/vars/fake" + "github.com/jmartin82/mmock/pkg/vars/fake" "log" "reflect" "regexp" diff --git a/internal/vars/fake/credit_card.go b/pkg/vars/fake/credit_card.go similarity index 100% rename from internal/vars/fake/credit_card.go rename to pkg/vars/fake/credit_card.go diff --git a/internal/vars/fake/generator.go b/pkg/vars/fake/generator.go similarity index 100% rename from internal/vars/fake/generator.go rename to pkg/vars/fake/generator.go diff --git a/internal/vars/fake/provider.go b/pkg/vars/fake/provider.go similarity index 100% rename from internal/vars/fake/provider.go rename to pkg/vars/fake/provider.go diff --git a/internal/vars/fake/provider_test.go b/pkg/vars/fake/provider_test.go similarity index 100% rename from internal/vars/fake/provider_test.go rename to pkg/vars/fake/provider_test.go diff --git a/internal/vars/filler.go b/pkg/vars/filler.go similarity index 94% rename from internal/vars/filler.go rename to pkg/vars/filler.go index dbcb51c..aa0a9b3 100644 --- a/internal/vars/filler.go +++ b/pkg/vars/filler.go @@ -1,7 +1,7 @@ package vars import ( - "github.com/jmartin82/mmock/internal/vars/fake" + "github.com/jmartin82/mmock/pkg/vars/fake" "github.com/jmartin82/mmock/pkg/mock" ) diff --git a/internal/vars/request.go b/pkg/vars/request.go similarity index 100% rename from internal/vars/request.go rename to pkg/vars/request.go diff --git a/internal/vars/request_test.go b/pkg/vars/request_test.go similarity index 100% rename from internal/vars/request_test.go rename to pkg/vars/request_test.go diff --git a/internal/vars/stream.go b/pkg/vars/stream.go similarity index 100% rename from internal/vars/stream.go rename to pkg/vars/stream.go diff --git a/internal/vars/stream_test.go b/pkg/vars/stream_test.go similarity index 100% rename from internal/vars/stream_test.go rename to pkg/vars/stream_test.go