github.com/oNaiPs/go-generate-fast@v0.3.0/src/plugins/moq/moq_test.go (about)

     1  package plugin_moq
     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 TestMoqPlugin_Name(t *testing.T) {
    14  	p := &MoqPlugin{}
    15  	assert.Equal(t, "moq", p.Name())
    16  }
    17  
    18  func TestMoqPlugin_Matches(t *testing.T) {
    19  	p := &MoqPlugin{}
    20  	assert.True(t, p.Matches(plugins.GenerateOpts{
    21  		ExecutableName: "moq",
    22  	}))
    23  }
    24  
    25  func TestMoqPlugin_ComputeInputOutputFiles(t *testing.T) {
    26  	p := &MoqPlugin{}
    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(`
    32  package example
    33  type Foo interface {
    34  	Bar(x int) int
    35  }
    36  `), 0644)
    37  	assert.NoError(t, err)
    38  
    39  	opts := plugins.GenerateOpts{
    40  		Path:           path.Join(tempDir, "test.go"),
    41  		ExecutableName: "moq",
    42  		SanitizedArgs: []string{
    43  			"-out", "output_file.go",
    44  			"-pkg", "example",
    45  			".",
    46  			"Foo",
    47  		},
    48  	}
    49  
    50  	_ = os.Chdir(tempDir)
    51  	ioFiles := p.ComputeInputOutputFiles(opts)
    52  	require.NotNil(t, ioFiles)
    53  	assert.Equal(t, []string{
    54  		path.Join(tempDir, "input_file1.go"),
    55  	}, ioFiles.InputFiles)
    56  	assert.Equal(t, []string{"output_file.go"}, ioFiles.OutputFiles)
    57  }