MCPcopy
hub / github.com/helm/helm / TestWaitJob

Function TestWaitJob

pkg/kube/client_test.go:797–855  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

795}
796
797func TestWaitJob(t *testing.T) {
798 job := newJob("starfish", 0, intToInt32(1), 0, 0)
799
800 var created *time.Time
801
802 c := newTestClient(t)
803 c.Factory.(*cmdtesting.TestFactory).Client = &fake.RESTClient{
804 NegotiatedSerializer: unstructuredSerializer,
805 Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
806 p, m := req.URL.Path, req.Method
807 t.Logf("got request %s %s", p, m)
808 switch {
809 case p == "/apis/batch/v1/namespaces/default/jobs/starfish" && m == http.MethodGet:
810 if created != nil && time.Since(*created) >= time.Second*5 {
811 job.Status.Succeeded = 1
812 }
813 return newResponse(http.StatusOK, job)
814 case p == "/namespaces/default/jobs" && m == http.MethodPost:
815 resources, err := c.Build(req.Body, false)
816 if err != nil {
817 t.Fatal(err)
818 }
819 now := time.Now()
820 created = &now
821 return newResponse(http.StatusOK, resources[0].Object)
822 default:
823 t.Fatalf("unexpected request: %s %s", req.Method, req.URL.Path)
824 return nil, nil
825 }
826 }),
827 }
828 var err error
829 c.Waiter, err = c.GetWaiterWithOptions(LegacyStrategy)
830 if err != nil {
831 t.Fatal(err)
832 }
833 resources, err := c.Build(objBody(job), false)
834 if err != nil {
835 t.Fatal(err)
836 }
837 result, err := c.Create(
838 resources,
839 ClientCreateOptionServerSideApply(false, false))
840
841 if err != nil {
842 t.Fatal(err)
843 }
844 if len(result.Created) != 1 {
845 t.Errorf("expected 1 resource created, got %d", len(result.Created))
846 }
847
848 if err := c.WaitWithJobs(resources, time.Second*30); err != nil {
849 t.Errorf("expected wait without error, got %s", err)
850 }
851
852 if time.Since(*created) < time.Second*5 {
853 t.Errorf("expected to wait at least 5 seconds before ready status was detected, but got %s", time.Since(*created))
854 }

Callers

nothing calls this directly

Calls 13

newJobFunction · 0.85
intToInt32Function · 0.85
newTestClientFunction · 0.85
newResponseFunction · 0.85
objBodyFunction · 0.85
FatalMethod · 0.80
NowMethod · 0.80
FatalfMethod · 0.80
BuildMethod · 0.65
GetWaiterWithOptionsMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…