Skip to content

Commit

Permalink
add test for config checker (stolostron#429)
Browse files Browse the repository at this point in the history
Signed-off-by: xuezhaojun <[email protected]>
  • Loading branch information
xuezhaojun authored Dec 16, 2021
1 parent dc05ae5 commit 1fcc350
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 99 deletions.
58 changes: 58 additions & 0 deletions cmd/agent/app/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package app

import (
"context"
"net/http"
"os"
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

addonutils "open-cluster-management.io/addon-framework/pkg/utils"
)

func TestServer(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Server Suite")
}

var tmpFileName string

var _ = BeforeSuite(func() {
tmpFile, err := os.CreateTemp("/tmp", "test")
Expect(err).To(BeNil())

tmpFileName = tmpFile.Name()

cc, err := addonutils.NewConfigChecker("test", tmpFileName)
Expect(err).To(BeNil())

go ServeHealthProbes(context.Background().Done(), ":8000", cc.Check)
})

var _ = Describe("Config changed", func() {
BeforeEach(func() {
// pre check
resp, err := http.Get("http://localhost:8000/healthz")
Expect(err).To(BeNil())
Expect(resp.StatusCode).To(Equal(http.StatusOK))

// change the config
err = os.WriteFile(tmpFileName, []byte("changed content"), os.ModeAppend)
Expect(err).To(BeNil())
})
It("should return false", func() {
// check
resp, err := http.Get("http://localhost:8000/healthz")
Expect(err).To(BeNil())
Expect(resp.StatusCode).To(Equal(http.StatusInternalServerError))

time.Sleep(3 * time.Second)
// check again
resp, err = http.Get("http://localhost:8000/healthz")
Expect(err).To(BeNil())
Expect(resp.StatusCode).To(Equal(http.StatusInternalServerError))
})
})
99 changes: 0 additions & 99 deletions test/e2e/config_checker_test.go

This file was deleted.

0 comments on commit 1fcc350

Please sign in to comment.