예제 #1
0
파일: shaman.go 프로젝트: nanopack/shaman
// ResetRecords resets all answers. If any nocache has any values, caching is skipped
func ResetRecords(resources *[]sham.Resource, nocache ...bool) error {
	for i := range *resources {
		(*resources)[i].Validate()
	}

	// new map to clear current answers
	answers := make(map[string]sham.Resource)

	for i := range *resources {
		answers[(*resources)[i].Domain] = (*resources)[i]
	}

	if len(nocache) == 0 {
		// store in cache
		config.Log.Trace("Resetting records in persistent cache...")
		err := cache.ResetRecords(resources)
		if err != nil {
			return err
		}
	}

	// reset the answers
	// todo: atomic
	Answers = answers

	return nil
}
예제 #2
0
// test nil cache resetRecords
func TestNoneResetRecords(t *testing.T) {
	noneReset()
	err := cache.ResetRecords(&[]shaman.Resource{})
	if err != nil {
		t.Errorf("Failed to reset records in none cacher - %v", err)
	}
}
예제 #3
0
// test scribble cache resetRecords
func TestScribbleResetRecords(t *testing.T) {
	scribbleReset()
	err := cache.ResetRecords(&nanoBoth)
	if err != nil {
		t.Errorf("Failed to reset records in scribble cacher - %v", err)
	}
}
예제 #4
0
// test scribble cache listRecords
func TestScribbleListRecords(t *testing.T) {
	scribbleReset()
	_, err := cache.ListRecords()
	cache.ResetRecords(&nanoBoth)
	_, err2 := cache.ListRecords()
	if err != nil || err2 != nil {
		t.Errorf("Failed to list records in scribble cacher - %v%v", err, err2)
	}
}