package buildstep import ( "os" "path/filepath" "testing" ) // 1887/A7: the node's build capacity is the build module's setting, read at every pull: the control-node at 0 pulls // nothing, a change takes effect at the next read, and a setting that cannot be read pulls nothing. func TestNodeCapacity(t *testing.T) { if got := NodeCapacity("", DefaultCapacities, "novox", nil)(); got != 0 { t.Errorf("novox = %d by default, want 0", got) } if got := NodeCapacity("", DefaultCapacities, "shanks", nil)(); got != 3 { t.Errorf("shanks = %d by default, want 3", got) } file := filepath.Join(t.TempDir(), "settings.json") os.WriteFile(file, []byte(`{"capacity":"shanks=1,ace=2"}`), 0o600) capacity := NodeCapacity(file, DefaultCapacities, "shanks", nil) if got := capacity(); got != 1 { t.Errorf("shanks = %d from the file, want 1", got) } os.WriteFile(file, []byte(`{"capacity":"shanks=4"}`), 0o600) if got := capacity(); got != 4 { t.Errorf("shanks = %d after the change, want 4", got) } if got := NodeCapacity(file, "", "pi", nil)(); got != 1 { t.Errorf("a node not named = %d, want 1", got) } os.WriteFile(file, []byte(`{"capacity":"shanks=lots"}`), 0o600) if got := capacity(); got != 0 { t.Errorf("an unreadable setting = %d, want 0", got) } if got := NodeCapacity(filepath.Join(t.TempDir(), "none"), DefaultCapacities, "shanks", nil)(); got != 0 { t.Errorf("a missing file = %d, want 0", got) } }