CFG_VER/APP_VER in the env file: invalid configs replaced, updates follow APP_VER (dev/stable/pin)
This commit is contained in:
@@ -21,8 +21,8 @@ var allSettingNames = []string{
|
||||
func TestSampleEnv(t *testing.T) {
|
||||
sample := SampleEnv("v0.1.7", sampleLogPath)
|
||||
|
||||
if !strings.HasPrefix(sample, "# gpu-turnstile version: v0.1.7\n") {
|
||||
t.Errorf("first line does not carry the version marker: %q", strings.SplitN(sample, "\n", 2)[0])
|
||||
if !strings.HasPrefix(sample, "CFG_VER=v0.1.7\n") {
|
||||
t.Errorf("first line does not carry CFG_VER: %q", strings.SplitN(sample, "\n", 2)[0])
|
||||
}
|
||||
|
||||
// Every setting known to Load must appear.
|
||||
@@ -32,22 +32,29 @@ func TestSampleEnv(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The sample must parse cleanly, and only LOG_FILE is active.
|
||||
// The sample must parse cleanly; active values are CFG_VER, APP_VER
|
||||
// and LOG_FILE.
|
||||
values, err := ParseEnvFile(strings.NewReader(sample))
|
||||
if err != nil {
|
||||
t.Fatalf("sample does not parse: %v", err)
|
||||
}
|
||||
if len(values) != 1 || values["LOG_FILE"] != sampleLogPath {
|
||||
t.Fatalf("active values = %v, want only LOG_FILE", values)
|
||||
want := map[string]string{"CFG_VER": "v0.1.7", "APP_VER": "stable", "LOG_FILE": sampleLogPath}
|
||||
if len(values) != len(want) {
|
||||
t.Fatalf("active values = %v, want %v", values, want)
|
||||
}
|
||||
for k, v := range want {
|
||||
if values[k] != v {
|
||||
t.Errorf("%s = %q, want %q", k, values[k], v)
|
||||
}
|
||||
}
|
||||
|
||||
// Without a log path everything is commented out.
|
||||
// Without a log path LOG_FILE stays commented out.
|
||||
values, err = ParseEnvFile(strings.NewReader(SampleEnv("v0.1.7", "")))
|
||||
if err != nil {
|
||||
t.Fatalf("sample without log path does not parse: %v", err)
|
||||
}
|
||||
if len(values) != 0 {
|
||||
t.Fatalf("active values = %v, want none", values)
|
||||
if len(values) != 2 || values["LOG_FILE"] != "" {
|
||||
t.Fatalf("active values = %v, want only CFG_VER and APP_VER", values)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +67,8 @@ func TestSyncSample(t *testing.T) {
|
||||
if !changed {
|
||||
t.Fatal("older installer file was not upgraded")
|
||||
}
|
||||
if !strings.HasPrefix(out, "# gpu-turnstile version: v0.1.7\n") {
|
||||
t.Error("marker was not updated to the new version")
|
||||
if !strings.Contains(out, "\nCFG_VER=v0.1.7\n") && !strings.HasPrefix(out, "CFG_VER=v0.1.7\n") {
|
||||
t.Error("CFG_VER was not updated to the new version")
|
||||
}
|
||||
if !strings.Contains(out, "#UPDATE_ASSET=gpu-turnstile.exe") {
|
||||
t.Error("missing setting was not appended")
|
||||
@@ -84,10 +91,11 @@ func TestSyncSample(t *testing.T) {
|
||||
t.Error("newer-version file was modified")
|
||||
}
|
||||
|
||||
// Hand-written configs (no marker) are never touched.
|
||||
// Files without CFG_VER are not installer-written; the installer
|
||||
// replaces them, SyncSample leaves them alone.
|
||||
user := "OLLAMA_URL=http://host:11434\n"
|
||||
if out, changed := SyncSample(user, "v0.1.7", sampleLogPath); changed || out != user {
|
||||
t.Error("hand-written config was modified")
|
||||
t.Error("file without CFG_VER was modified")
|
||||
}
|
||||
|
||||
// A dev build never upgrades.
|
||||
@@ -96,6 +104,24 @@ func TestSyncSample(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncSampleAppendsMissingAppVer(t *testing.T) {
|
||||
old := SampleEnv("v0.1.6", sampleLogPath)
|
||||
old = strings.Replace(old, "# "+appVerComment+"\n", "", 1)
|
||||
old = strings.Replace(old, "APP_VER=stable\n", "", 1)
|
||||
|
||||
out, changed := SyncSample(old, "v0.1.7", sampleLogPath)
|
||||
if !changed {
|
||||
t.Fatal("file without APP_VER was not upgraded")
|
||||
}
|
||||
values, err := ParseEnvFile(strings.NewReader(out))
|
||||
if err != nil {
|
||||
t.Fatalf("upgraded file does not parse: %v", err)
|
||||
}
|
||||
if values["APP_VER"] != "stable" {
|
||||
t.Fatalf("APP_VER = %q, want appended default \"stable\"", values["APP_VER"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareVersions(t *testing.T) {
|
||||
cases := []struct {
|
||||
a, b string
|
||||
|
||||
Reference in New Issue
Block a user