Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
panic when stop channel was not set & add Tests for this
Browse files Browse the repository at this point in the history
  • Loading branch information
wayilau committed Mar 25, 2019
2 parents 4e7e094 + 53d7cd1 commit b1059e5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
1 change: 0 additions & 1 deletion cmd/apiserver/app/server/run_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func RunServer(opts *ServiceCatalogServerOptions, stopCh <-chan struct{}) error
if stopCh == nil {
/* the caller of RunServer should generate the stop channel
if there is a need to stop the API server */
// stopCh = server.SetupSignalHandler()
panic("stop channel was not set when starting the api server")
}

Expand Down
35 changes: 35 additions & 0 deletions pkg/hyperkube/hyperkube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"k8s.io/apimachinery/pkg/util/wait"

"github.com/kubernetes-incubator/service-catalog/cmd/apiserver/app/server"
"github.com/kubernetes-incubator/service-catalog/test/util"
)

Expand All @@ -46,6 +47,7 @@ func testServer(n string) *Server {
},
}
}

func testServerError(n string) *Server {
return &Server{
SimpleUsage: n,
Expand Down Expand Up @@ -320,3 +322,36 @@ func TestCobraSubCommandMessage(t *testing.T) {
x := runFull(t, "hyperkube test-cobra-command subcommand --submsg foobar", wait.NeverStop)
util.AssertContains(t, x.output, "submsg: foobar")
}

func testRunServer(n string) *Server {
s := server.NewServiceCatalogServerOptions()
return &Server{
PrimaryName: "testserver",
AlternativeName: "service-catalog-testserver",
SimpleUsage: "testserver",
Long: fmt.Sprintf("A simple server named %s", n),
Run: func(_ *Server, args []string, stopCh <-chan struct{}) error {
return server.RunServer(s, stopCh)
},
RespectsStopCh: true,
}
}

func TestStopChannelWithRespectsStopCh(t *testing.T) {
expect := fmt.Errorf("%v", "stop channel was not set when starting the api server")
hk := HyperKube{
Name: "hyperkube",
Long: "hyperkube is an all-in-one server binary.",
}

hk.AddServer(testRunServer("test1"))
args := []string{"testserver"}

defer func() {
if value := recover(); value != nil {
util.AssertEqualError(t, expect, value.(string))
}
}()

hk.Run(args, nil)
}

0 comments on commit b1059e5

Please sign in to comment.