Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
use tmp file
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Aug 24, 2018
1 parent 2ffbd5a commit 52acb3f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions conf/indexrules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package conf

import (
"io/ioutil"
"os"
"regexp"
"testing"
"time"
Expand Down Expand Up @@ -68,11 +69,19 @@ max-stale = 7d
},
}
for i, c := range cases {
err := ioutil.WriteFile("/tmp/indexrules-test-readindexrules", []byte(c.in), 0644)
tmpfile, err := ioutil.TempFile("", "indexrules-test-readindexrules")
if err != nil {
panic(err)
}
rules, err := ReadIndexRules("/tmp/indexrules-test-readindexrules")

if _, err := tmpfile.Write([]byte(c.in)); err != nil {
panic(err)
}
if err := tmpfile.Close(); err != nil {
panic(err)
}

rules, err := ReadIndexRules(tmpfile.Name())
if (err != nil) != c.expErr {
t.Fatalf("case %d, exp err %t, got err %v", i, c.expErr, err)
}
Expand All @@ -92,6 +101,8 @@ max-stale = 7d
t.Fatalf("case %d, exp rules %v, got %v", i, c.expRules, rules)
}
}

os.Remove(tmpfile.Name())
}
}
func TestIndexRulesMatch(t *testing.T) {
Expand Down

0 comments on commit 52acb3f

Please sign in to comment.