From 493262345520f7e733ea795b837d8f0c4b9fabc7 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Thu, 28 Sep 2023 15:34:19 -0500 Subject: [PATCH] fix case typo in generator name --- flixkit.go | 25 ------------------------- flixkit_test.go | 22 +++------------------- javascript.go | 4 ++-- javascript_test.go | 8 ++++---- 4 files changed, 9 insertions(+), 50 deletions(-) diff --git a/flixkit.go b/flixkit.go index 55e6ebe..a916310 100644 --- a/flixkit.go +++ b/flixkit.go @@ -19,7 +19,6 @@ type FlixService interface { GetFlix(ctx context.Context, templateName string) (*FlowInteractionTemplate, error) GetFlixByIDRaw(ctx context.Context, templateID string) (string, error) GetFlixByID(ctx context.Context, templateID string) (*FlowInteractionTemplate, error) - GenFlixBinding(ctx context.Context, templateID string, isLocal bool, generator Generator) (string, error) } // OsFileReader is a real implementation that calls os.ReadFile. @@ -94,30 +93,6 @@ func (s *flixServiceImpl) GetFlixByID(ctx context.Context, templateID string) (* return parsedTemplate, nil } - -func (s *flixServiceImpl) GenFlixBinding(ctx context.Context, templateLocation string, isLocal bool, generator Generator) (string, error) { - var template string - var err error - if isLocal { - template, err = FetchFlixWithContextFromFile(ctx, s.config.FileReader, templateLocation) - } else { - template, err = FetchFlixWithContext(ctx, templateLocation) - } - - if err != nil { - return "", err - } - - parsedTemplate, err := ParseFlix(template) - if err != nil { - return "", err - } - - contents, bindingErr := generator.Generate(parsedTemplate, templateLocation, isLocal) - - return contents, bindingErr -} - func ParseFlix(template string) (*FlowInteractionTemplate, error) { var flowTemplate FlowInteractionTemplate diff --git a/flixkit_test.go b/flixkit_test.go index 746a7e6..e879d14 100644 --- a/flixkit_test.go +++ b/flixkit_test.go @@ -7,7 +7,6 @@ import ( "net/http" "net/http/httptest" "testing" - "testing/fstest" "github.com/hexops/autogold/v2" "github.com/stretchr/testify/assert" @@ -332,22 +331,14 @@ func TestGenFlixJS(t *testing.T) { defer server.Close() templatePath := "templateID" - fsys := fstest.MapFS{ - "templateID": &fstest.MapFile{Data: []byte(flix_template)}, - } - - flixService := NewFlixService(&Config{FlixServerURL: server.URL, FileReader: fsys}) - - ctx := context.Background() - - out, err := flixService.GenFlixBinding(ctx, templatePath, true, JavaScriptGenerator{}) + out, err := JavascriptGenerator.Generate(JavascriptGenerator{}, parsedTemplate, templatePath, true) autogold.ExpectFile(t, out) assert.NoError(err, "GenFlixBinding should not return an error") } func TestGenRemoteFlixJS(t *testing.T) { assert := assert.New(t) - //l, _ := net.Listen("tcp", "127.0.0.1:52718") + handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Write([]byte(flix_template)) }) @@ -364,15 +355,8 @@ func TestGenRemoteFlixJS(t *testing.T) { server.Start() defer server.Close() - fsys := fstest.MapFS{ - "templatePath": {}, - } - - flixService := NewFlixService(&Config{FlixServerURL: server.URL, FileReader: fsys}) - - ctx := context.Background() endpoint := server.URL + "/tempateName" - out, err := flixService.GenFlixBinding(ctx, endpoint, false, JavaScriptGenerator{}) + out, err := JavascriptGenerator.Generate(JavascriptGenerator{}, parsedTemplate, endpoint, false) assert.NoError(err, "GenFlixBinding should not return an error") autogold.ExpectFile(t, out) } \ No newline at end of file diff --git a/javascript.go b/javascript.go index 2d0e7e4..fb30ba7 100644 --- a/javascript.go +++ b/javascript.go @@ -30,9 +30,9 @@ type TemplateData struct { //go:embed templates/*.tmpl var templateFiles embed.FS -type JavaScriptGenerator struct{} +type JavascriptGenerator struct{} -func (g JavaScriptGenerator) Generate(flix *FlowInteractionTemplate, templateLocation string, isLocal bool) (string, error) { +func (g JavascriptGenerator) Generate(flix *FlowInteractionTemplate, templateLocation string, isLocal bool) (string, error) { tmpl, err := template.ParseFS(templateFiles, "templates/*.tmpl") if err != nil { return "", err diff --git a/javascript_test.go b/javascript_test.go index 1a9d1c4..70fc233 100644 --- a/javascript_test.go +++ b/javascript_test.go @@ -182,13 +182,13 @@ var minimumTemplate = &FlowInteractionTemplate{ }, } func TestJSGenTransaction(t *testing.T) { - generator := JavaScriptGenerator{} + generator := JavascriptGenerator{} got, _ := generator.Generate(parsedTemplateTX, "./transfer_token.json", true) autogold.ExpectFile(t, got) } func TestJSGenScript(t *testing.T) { - generator := JavaScriptGenerator{} + generator := JavascriptGenerator{} assert := assert.New(t) got, err:= generator.Generate(parsedTemplateScript, "./multiply_two_integers.template.json", true) assert.NoError(err, "ParseTemplate should not return an error") @@ -196,7 +196,7 @@ func TestJSGenScript(t *testing.T) { } func TestJSGenArrayScript(t *testing.T) { - generator := JavaScriptGenerator{} + generator := JavascriptGenerator{} assert := assert.New(t) out, err := generator.Generate(ArrayTypeScript, "./multiply-numbers.template.json", true) @@ -205,7 +205,7 @@ func TestJSGenArrayScript(t *testing.T) { } func TestJSGenMinScript(t *testing.T) { - generator := JavaScriptGenerator{} + generator := JavascriptGenerator{} assert := assert.New(t) out, err := generator.Generate(minimumTemplate, "./min.template.json", true)