-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from sev-2/feature/integrate-gofmt
feature(generate) use go format in model generator
- Loading branch information
Showing
4 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package generator_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sev-2/raiden/pkg/generator" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGenerate_ErrorWritingToFile(t *testing.T) { | ||
invalidPath := "/invalid_path/output.txt" | ||
|
||
tmpl := "{{ .Name }}" | ||
input := generator.GenerateInput{ | ||
BindData: struct{ Name string }{"John"}, | ||
Template: tmpl, | ||
TemplateName: "testTemplate", | ||
OutputPath: invalidPath, | ||
} | ||
|
||
err := generator.Generate(input, nil) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "failed create file") | ||
} | ||
|
||
func TestGenerate_ErrorParsingTemplate(t *testing.T) { | ||
input := generator.GenerateInput{ | ||
BindData: nil, | ||
Template: "{{ .invalid}", | ||
TemplateName: "testTemplate", | ||
OutputPath: "test_output.txt", | ||
} | ||
|
||
err := generator.Generate(input, nil) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "error parsing") | ||
} | ||
|
||
func TestGenerate_ErrorExecutingTemplate(t *testing.T) { | ||
tmpl := "{{ .Name }}" | ||
input := generator.GenerateInput{ | ||
BindData: struct{}{}, | ||
Template: tmpl, | ||
TemplateName: "testTemplate", | ||
OutputPath: "test_output.txt", | ||
} | ||
|
||
err := generator.Generate(input, nil) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "error execute template") | ||
} | ||
|
||
// Test for FileWriter Write function | ||
func TestFileWriter_Write_ErrorCreatingFile(t *testing.T) { | ||
invalidPath := "/invalid_path/output.txt" // Simulating an invalid path | ||
|
||
fw := &generator.FileWriter{FilePath: invalidPath} | ||
_, err := fw.Write([]byte("test content")) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "failed create file") | ||
} | ||
|
||
func TestFileWriter_Write_ErrorFormattingCode(t *testing.T) { | ||
validPath := "test_err_output_formatting.txt" | ||
|
||
fw := &generator.FileWriter{FilePath: validPath} | ||
|
||
input := generator.GenerateInput{ | ||
BindData: struct{ Name string }{"invalid code"}, | ||
Template: "{{ .Name }}", | ||
TemplateName: "testTemplate", | ||
} | ||
|
||
err := generator.Generate(input, fw) | ||
assert.Contains(t, err.Error(), "error format code") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters