Skip to content
go-libfossil Artifact [589bb435af]
Login

Artifact [589bb435af]

Artifact 589bb435af844bc405d4e805e690cf79efc3b21749e69aa7c835a6ddcef354e8:


package main

import (
	"os/exec"
	"path/filepath"
	"strings"
	"testing"
)

const (
	moderncDriverImportPath = "github.com/danmestas/go-libfossil/db/driver/modernc"
	ncrucesDriverImportPath = "github.com/danmestas/go-libfossil/db/driver/ncruces"
)

func assertDriverDependencySelection(t *testing.T, tag, expected, unexpected string) {
	t.Helper()

	args := []string{"list", "-deps", "-f={{.ImportPath}}"}
	if tag != "" {
		args = append(args, "-tags", tag)
	}
	args = append(args, "./cmd/libfossil")

	cmd := exec.Command("go", args...)
	cmd.Dir = filepath.Join("..", "..")
	output, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatalf("go list dependencies: %v\n%s", err, output)
	}

	dependencies := make(map[string]struct{})
	for _, dependency := range strings.Fields(string(output)) {
		dependencies[dependency] = struct{}{}
	}
	if _, ok := dependencies[expected]; !ok {
		t.Errorf("go list dependencies missing selected driver %q", expected)
	}
	if _, ok := dependencies[unexpected]; ok {
		t.Errorf("go list dependencies included unselected driver %q", unexpected)
	}
}