-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a quick unit test for PostprocessGoFile error management on disco…
…vered imports
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package gocode | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPostprocessGoFile_withDiscoveredImport(t *testing.T) { | ||
req := require.New(t) | ||
input := GenGoFile{ | ||
Path: "file.go", | ||
In: []byte(`package thema | ||
func Hello(name string) string { | ||
return fmt.Sprintf("Hello %w", name) | ||
}`), | ||
IgnoreDiscoveredImports: false, | ||
} | ||
|
||
_, err := PostprocessGoFile(input) | ||
req.Error(err) | ||
req.ErrorContains(err, "goimports added the following import statements") | ||
} | ||
|
||
func TestPostprocessGoFile_withIgnoredDiscoveredImport(t *testing.T) { | ||
req := require.New(t) | ||
input := GenGoFile{ | ||
Path: "file.go", | ||
In: []byte(`package thema | ||
func Hello(name string) string { | ||
return fmt.Sprintf("Hello %w", name) | ||
}`), | ||
IgnoreDiscoveredImports: true, | ||
} | ||
|
||
output, err := PostprocessGoFile(input) | ||
req.NoError(err) | ||
|
||
req.Equal(`package thema | ||
import "fmt" | ||
func Hello(name string) string { | ||
return fmt.Sprintf("Hello %w", name) | ||
} | ||
`, string(output)) | ||
} |