github.com/oNaiPs/go-generate-fast@v0.3.0/src/plugins/stringer/stringer_test.go (about) 1 package plugin_stringer 2 3 import ( 4 "os" 5 "path" 6 "testing" 7 8 "github.com/oNaiPs/go-generate-fast/src/plugins" 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestStringerPlugin_Name(t *testing.T) { 14 p := &StringerPlugin{} 15 assert.Equal(t, "stringer", p.Name()) 16 } 17 18 func TestStringerPlugin_Matches(t *testing.T) { 19 p := &StringerPlugin{} 20 assert.True(t, p.Matches(plugins.GenerateOpts{ 21 ExecutableName: "stringer", 22 })) 23 } 24 25 func TestStringerPlugin_ComputeInputOutputFiles(t *testing.T) { 26 p := &StringerPlugin{} 27 tempDir := t.TempDir() 28 29 err := os.WriteFile(path.Join(tempDir, "go.mod"), []byte("module example.com/mod"), 0644) 30 assert.NoError(t, err) 31 err = os.WriteFile(path.Join(tempDir, "input_file1.go"), []byte("package ex"), 0644) 32 assert.NoError(t, err) 33 err = os.WriteFile(path.Join(tempDir, "input_file2.go"), []byte("package ex"), 0644) 34 assert.NoError(t, err) 35 36 opts := plugins.GenerateOpts{ 37 Path: path.Join(tempDir, "test.go"), 38 ExecutableName: "stringer", 39 SanitizedArgs: []string{"-type", "MyType", "-output", "output_file.go"}, 40 } 41 42 err = os.Chdir(tempDir) 43 assert.NoError(t, err) 44 cwd, err := os.Getwd() 45 assert.NoError(t, err) 46 ioFiles := p.ComputeInputOutputFiles(opts) 47 require.NotNil(t, ioFiles) 48 assert.Equal(t, []string{ 49 path.Join(cwd, "input_file1.go"), 50 path.Join(cwd, "input_file2.go"), 51 }, ioFiles.InputFiles) 52 assert.Equal(t, []string{"output_file.go"}, ioFiles.OutputFiles) 53 }