Skip to content

Commit

Permalink
fix case typo in generator name
Browse files Browse the repository at this point in the history
  • Loading branch information
bthaile committed Sep 28, 2023
1 parent e7cd1bc commit 4932623
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 50 deletions.
25 changes: 0 additions & 25 deletions flixkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
22 changes: 3 additions & 19 deletions flixkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"net/http/httptest"
"testing"
"testing/fstest"

"github.com/hexops/autogold/v2"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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))
})
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions javascript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,21 @@ 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")
autogold.ExpectFile(t, got)
}

func TestJSGenArrayScript(t *testing.T) {
generator := JavaScriptGenerator{}
generator := JavascriptGenerator{}
assert := assert.New(t)

out, err := generator.Generate(ArrayTypeScript, "./multiply-numbers.template.json", true)
Expand All @@ -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)
Expand Down

0 comments on commit 4932623

Please sign in to comment.