Categorygithub.com/omegion/go-command
modulepackage
0.1.0
Repository: https://github.com/omegion/go-command.git
Documentation: pkg.go.dev

# README

go-command

GithubBuild Coverage Status Go Report Card GoDoc

exec.Command wrapper for better testing.

How does it work?

const dummyCommand = "dummy"

type Foo struct {
    Commander command.Interface
}

func (f Foo) Run() error {
    _, err := f.Commander.Output(dummyCommand)
    if err != nil {
        return err
    }

    return nil
}

func TestCommand_Output(t *testing.T) {
    ctrl := gomock.NewController(t)
    
    defer ctrl.Finish()
    
    m := mocks.NewMockInterface(ctrl)
    
    m.EXPECT().Output(dummyCommand).Return([]byte{}, nil)
    
    foo := Foo{
        Commander: m,
    }
    
    err := foo.Run()
    assert.Equal(t, err, nil)
}

# Packages

Package mocks is a generated GoMock package.

# Structs

Command is custom wrapper for exec.Command.

# Interfaces

go:generate mockgen -destination=mocks/commander_mock.go -package=mocks github.com/omegion/go-command Interface Interface is an interface for Command.