package resolution import ( "strings" "testing" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) // pulledInBy is a module that requires what raw's module provides, so resolving it alone pulls that module in. const pulledInBy = `{"module":"desk","version":"1","requires":["pulled-in-here"]}` // providing is raw's module providing what desk requires. func providing(raw string) string { return strings.Replace(raw, `"version":"1",`, `"version":"1","provides":[{"name":"pulled-in-here"}],`, 1) } // onWorkstation resolves m on the workstation either assigned beside desk, or pulled in by desk alone. func onWorkstation(t *testing.T, m mcat.Manifest, assigned bool) mcat.Resolution { t.Helper() desk, err := decodeForTest([]byte(pulledInBy)) if err != nil { t.Fatal(err) } want := []string{"desk"} if assigned { want = append(want, m.Module) } r, err := Resolve(shelf(m, desk), want, workstation(), mcat.World{}) if err != nil { t.Fatal(err) } why := map[bool]string{true: "assigned", false: "required by desk"}[assigned] if r.Because[m.Module] != why { t.Fatalf("%s is on the workstation because %q, want %q", m.Module, r.Because[m.Module], why) } r.Account = "op" return r } // What requires a module pulled in is said by name, for its value in the assignments mirror; nothing for one // assigned. func TestAPulledInModuleSaysWhatRequiresIt(t *testing.T) { m := held(t, providing(notifierMoved()), builtNotifier()) if by := RequiredBy(onWorkstation(t, m, false), "notify"); by != "desk" { t.Errorf("pulled in, notify is required by %q, want desk", by) } assigned := onWorkstation(t, m, true) if by := RequiredBy(assigned, "notify"); by != "" { t.Errorf("assigned, notify is required by %q", by) } if by := RequiredBy(assigned, "absent"); by != "" { t.Errorf("a module not on the machine is required by %q", by) } }