test API

test

package

API reference for the test package.

S
struct

plugin

cmd/rfw/plugins/test/test.go:12-12
type plugin struct

Methods

Name
Method

Returns

string
func (*plugin) Name() string
{ return "test" }
Priority
Method

Returns

int
func (*plugin) Priority() int
{ return 0 }
Build
Method

Parameters

Returns

error
func (*plugin) Build(raw json.RawMessage) error
{
	cfg := struct {
		Packages []string `json:"packages"`
	}{Packages: []string{"./..."}}
	if len(raw) > 0 {
		_ = json.Unmarshal(raw, &cfg)
	}
	args := append([]string{"test"}, cfg.Packages...)
	cmd := exec.Command("go", args...)
	output, err := cmd.CombinedOutput()
	out := strings.TrimSpace(string(output))
	if err != nil {
		logging.Log.Error("go test failed", logging.F("plugin", "test"), logging.F("output", out), logging.F("error", err.Error()))
		return err
	}
	logging.Log.Info("go test ok", logging.F("plugin", "test"), logging.F("output", out))
	return nil
}
ShouldRebuild
Method

Parameters

path string

Returns

bool
func (*plugin) ShouldRebuild(path string) bool
{
	return strings.HasSuffix(path, "_test.go")
}
F
function

init

cmd/rfw/plugins/test/test.go:14-14
func init()

{ plugins.Register(&plugin{}) }
F
function

TestShouldRebuild

TestShouldRebuild verifies that the test plugin triggers rebuilds for Go test
files only.

Parameters

cmd/rfw/plugins/test/test_test.go:7-15
func TestShouldRebuild(t *testing.T)

{
	p := &plugin{}
	if !p.ShouldRebuild("foo_test.go") {
		t.Fatalf("expected rebuild for _test.go files")
	}
	if p.ShouldRebuild("main.go") {
		t.Fatalf("non-test files should not trigger rebuild")
	}
}