package main import "testing" func TestRequirement(t *testing.T) { graph := "uberbringer modernc.org/sqlite@v1.64.0\n" + "uberbringer modernc.org/libc@v1.82.14\n" + "modernc.org/sqlite@v1.63.0 modernc.org/libc@v1.79.0\n" + "modernc.org/sqlite@v1.64.0 golang.org/x/sys@v0.49.0\n" + "modernc.org/sqlite@v1.64.0 modernc.org/libc@v1.80.1\n" + "modernc.org/libc@v1.80.1 modernc.org/memory@v1.12.1\n" tests := []struct { name, module, path, want string }{ {"the driver's own requirement", "modernc.org/sqlite@v1.64.0", "modernc.org/libc", "v1.80.1"}, {"another version of the driver", "modernc.org/sqlite@v1.63.0", "modernc.org/libc", "v1.79.0"}, {"a module the driver does not require", "modernc.org/sqlite@v1.64.0", "modernc.org/memory", ""}, {"a driver version not in the graph", "modernc.org/sqlite@v1.65.0", "modernc.org/libc", ""}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := requirement(graph, tt.module, tt.path) if got != tt.want || (err != nil) != (tt.want == "") { t.Errorf("requirement = %q, %v; want %q", got, err, tt.want) } }) } }