Skip to content

Commit 1fcc350

Browse files
authored
add test for config checker (#429)
Signed-off-by: xuezhaojun <[email protected]>
1 parent dc05ae5 commit 1fcc350

File tree

2 files changed

+58
-99
lines changed

2 files changed

+58
-99
lines changed

cmd/agent/app/server_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package app
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"os"
7+
"testing"
8+
"time"
9+
10+
. "github.com/onsi/ginkgo"
11+
. "github.com/onsi/gomega"
12+
13+
addonutils "open-cluster-management.io/addon-framework/pkg/utils"
14+
)
15+
16+
func TestServer(t *testing.T) {
17+
RegisterFailHandler(Fail)
18+
RunSpecs(t, "Server Suite")
19+
}
20+
21+
var tmpFileName string
22+
23+
var _ = BeforeSuite(func() {
24+
tmpFile, err := os.CreateTemp("/tmp", "test")
25+
Expect(err).To(BeNil())
26+
27+
tmpFileName = tmpFile.Name()
28+
29+
cc, err := addonutils.NewConfigChecker("test", tmpFileName)
30+
Expect(err).To(BeNil())
31+
32+
go ServeHealthProbes(context.Background().Done(), ":8000", cc.Check)
33+
})
34+
35+
var _ = Describe("Config changed", func() {
36+
BeforeEach(func() {
37+
// pre check
38+
resp, err := http.Get("http://localhost:8000/healthz")
39+
Expect(err).To(BeNil())
40+
Expect(resp.StatusCode).To(Equal(http.StatusOK))
41+
42+
// change the config
43+
err = os.WriteFile(tmpFileName, []byte("changed content"), os.ModeAppend)
44+
Expect(err).To(BeNil())
45+
})
46+
It("should return false", func() {
47+
// check
48+
resp, err := http.Get("http://localhost:8000/healthz")
49+
Expect(err).To(BeNil())
50+
Expect(resp.StatusCode).To(Equal(http.StatusInternalServerError))
51+
52+
time.Sleep(3 * time.Second)
53+
// check again
54+
resp, err = http.Get("http://localhost:8000/healthz")
55+
Expect(err).To(BeNil())
56+
Expect(resp.StatusCode).To(Equal(http.StatusInternalServerError))
57+
})
58+
})

test/e2e/config_checker_test.go

-99
This file was deleted.

0 commit comments

Comments
 (0)