32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
package updater
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/shcizo/package-updater/internal/protocol"
|
|
)
|
|
|
|
func TestDispatch(t *testing.T) {
|
|
compose := execFunc(func(context.Context, protocol.JobStart, io.Writer) (string, error) { return "compose", nil })
|
|
swarm := execFunc(func(context.Context, protocol.JobStart, io.Writer) (string, error) { return "swarm", nil })
|
|
d := NewDispatch(compose, swarm)
|
|
|
|
got, err := d.Execute(context.Background(), protocol.JobStart{Kind: protocol.KindCompose}, io.Discard)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "compose", got)
|
|
|
|
got, err = d.Execute(context.Background(), protocol.JobStart{Kind: protocol.KindSwarm}, io.Discard)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "swarm", got)
|
|
|
|
_, err = d.Execute(context.Background(), protocol.JobStart{Kind: protocol.KindContainer}, io.Discard)
|
|
assert.ErrorContains(t, err, "cannot update")
|
|
_, err = d.Execute(context.Background(), protocol.JobStart{Kind: "weird"}, io.Discard)
|
|
assert.ErrorContains(t, err, "cannot update")
|
|
}
|