From a528dd802b52df473dc60da4e795c3f7f3b5ee1f Mon Sep 17 00:00:00 2001 From: Jan Halfar Date: Tue, 12 Jun 2018 14:27:42 +0200 Subject: [PATCH] prepared new version to 0.11.0 with async tc client support --- Makefile | 5 +++-- cmd/demo/demo.go | 10 +++++++++- cmd/gotsrpc/gotsrpc.go | 2 +- config/config.go | 6 ++++-- config/config_test.go | 28 ++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a6122f9..6038ff0 100644 --- a/Makefile +++ b/Makefile @@ -21,5 +21,6 @@ goreleaser: glide: @go get github.com/Masterminds/glide && glide install -test: demo - go test $(glide nv) +test: + go test -v ./... + diff --git a/cmd/demo/demo.go b/cmd/demo/demo.go index d0c3c5a..f790e7a 100644 --- a/cmd/demo/demo.go +++ b/cmd/demo/demo.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "net/http" + "os/exec" "strings" "github.com/foomo/gotsrpc/demo" @@ -41,6 +42,13 @@ func main() { d := &Demo{ proxy: demo.NewDefaultDemoGoTSRPCProxy(&demo.Demo{}, []string{}), } - fmt.Println("staring a demo on http://127.0.0.1:8080 - open it and take a look at the console") + fmt.Println("starting a demo server on http://127.0.0.1:8080 - open it and take a look at the console") + cmd := exec.Command("open", "http://127.0.0.1:8080") + go func() { + err := cmd.Run() + if err != nil { + fmt.Println("tried to open things with you default browser - did fail", err) + } + }() fmt.Println(http.ListenAndServe(":8080", d)) } diff --git a/cmd/gotsrpc/gotsrpc.go b/cmd/gotsrpc/gotsrpc.go index 3363c73..109832d 100644 --- a/cmd/gotsrpc/gotsrpc.go +++ b/cmd/gotsrpc/gotsrpc.go @@ -10,7 +10,7 @@ import ( "github.com/foomo/gotsrpc/config" ) -const Version = "0.10.0" +const Version = "0.11.0" func jsonDump(v interface{}) { jsonBytes, err := json.MarshalIndent(v, "", " ") diff --git a/config/config.go b/config/config.go index fd8d6c9..41593bb 100644 --- a/config/config.go +++ b/config/config.go @@ -89,6 +89,8 @@ func LoadConfigFile(file string) (conf *Config, err error) { return loadConfig(yamlBytes) } +var ErrInvalidTSClientFlavor = errors.New(fmt.Sprintln("unknown ts client flavor: must be empty or ", TSClientFlavorAsync)) + func loadConfig(yamlBytes []byte) (conf *Config, err error) { conf = &Config{} yamlErr := yaml.Unmarshal(yamlBytes, conf) @@ -99,13 +101,13 @@ func loadConfig(yamlBytes []byte) (conf *Config, err error) { switch conf.TSClientFlavor { case "", TSClientFlavorAsync: default: - err = errors.New("unknown ts client flavor: " + conf.TSClientFlavor + " must be empty or " + TSClientFlavorAsync) + err = ErrInvalidTSClientFlavor + return } switch conf.ModuleKind { case ModuleKindCommonJS, ModuleKindDefault: case "": conf.ModuleKind = ModuleKindDefault - default: err = errors.New(fmt.Sprintln("illegal module kind:", conf.ModuleKind, "must be in", ModuleKindDefault, ModuleKindCommonJS)) return diff --git a/config/config_test.go b/config/config_test.go index 0c9434e..255c823 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -60,4 +60,32 @@ func TestLoadConfig(t *testing.T) { if demoTarget.Services["/service/demo"] != "Service" { t.Fatal("first service is wrong") } + +} + +const sampleConfInvalidClientFlavor = `--- +tsclientflavor: asynci +targets: + demo: + services: + /service/demo: Service + package: github.com/foomo/gotsrpc/demo + module: My.Service + modulekind: commonjs + out: /tmp/my-service.ts +mappings: + foo/bar: + module: Sample.Module + out: path/to/ts + github.com/foomo/gotsrpc: + module: Sample.Module.RPC + out: path/to/other/folder + +` + +func TestLoadConfigInvalidClientFlavor(t *testing.T) { + _, err := loadConfig([]byte(sampleConfInvalidClientFlavor)) + if err == nil { + t.Fatal("that config must be invalid") + } }