Skip to content

Commit

Permalink
add ut for HealthyCheck
Browse files Browse the repository at this point in the history
Signed-off-by: hxcGit <houxc_mail@163.com>
  • Loading branch information
xavier-hou committed Sep 30, 2022
1 parent a269988 commit 100f17a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/yurthub/otaupdate/ota_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/gorilla/mux"
Expand All @@ -28,8 +29,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"

"github.com/openyurtio/openyurt/cmd/yurthub/app/config"
"github.com/openyurtio/openyurt/pkg/controller/daemonpodupdater"
"github.com/openyurtio/openyurt/pkg/yurthub/cachemanager"
"github.com/openyurtio/openyurt/pkg/yurthub/healthchecker"
"github.com/openyurtio/openyurt/pkg/yurthub/kubernetes/rest"
"github.com/openyurtio/openyurt/pkg/yurthub/storage/disk"
)

Expand Down Expand Up @@ -149,3 +153,26 @@ func TestUpdatePod(t *testing.T) {
}

}

func TestHealthyCheck(t *testing.T) {
u, _ := url.Parse("https://10.10.10.113:6443")
fakeHealthchecker := healthchecker.NewFakeChecker(false, nil)
cfg := &config.YurtHubConfiguration{
RemoteServers: []*url.URL{u},
}

rcm, err := rest.NewRestConfigManager(cfg, nil, fakeHealthchecker)
if err != nil {
t.Fatal(err)
}

req, err := http.NewRequest("POST", "", nil)
if err != nil {
t.Fatal(err)
}

rr := httptest.NewRecorder()

HealthyCheck(rcm, "", UpdatePod).ServeHTTP(rr, req)
assert.Equal(t, http.StatusForbidden, rr.Code)
}

0 comments on commit 100f17a

Please sign in to comment.