aboutsummaryrefslogtreecommitdiff
path: root/test/health_reload_test.go
blob: 042cd093ce095263dd30904b4bf3120ccd101384 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package test

import (
	"io/ioutil"
	"log"
	"net/http"
	"testing"
)

func TestHealthReload(t *testing.T) {
	log.SetOutput(ioutil.Discard)

	// Corefile with for example without proxy section.
	corefile := `example.org:0 {
	health localhost:35080
}
`
	i, err := CoreDNSServer(corefile)
	if err != nil {
		t.Fatalf("Could not get CoreDNS serving instance: %s", err)
	}

	resp, err := http.Get("http://localhost:35080/health")
	if err != nil {
		t.Fatalf("Could not get health: %s", err)
	}
	body, err := ioutil.ReadAll(resp.Body)
	if x := string(body); x != "OK" {
		t.Fatalf("Expect OK, got %s", x)
	}
	resp.Body.Close()

	i, err = i.Restart(NewInput(corefile))
	if err != nil {
		t.Fatalf("Could not restart CoreDNS serving instance: %s", err)
	}

	defer i.Stop()

	resp, err = http.Get("http://localhost:35080/health")
	if err != nil {
		t.Fatalf("Could not get health: %s", err)
	}
	body, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		t.Fatalf("Could not get resp.Body: %s", err)
	}
	if x := string(body); x != "OK" {
		t.Fatalf("Expect OK, got %s", x)
	}
	resp.Body.Close()
}