Skip to content

Commit

Permalink
tmp fix for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyufan2 committed Apr 11, 2024
1 parent 90f3493 commit f9668f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions cns/restserver/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,27 @@ func setEnv(t *testing.T) *httptest.ResponseRecorder {
return w
}

// Since UT can only run with localhost, to mock all api test cases, add nodeListener service handlers
func addHandlersToListener(service *HTTPRestService) {
// Add handlers for UT
listener := service.Listener

listener.AddHandler(cns.GetNetworkContainerByOrchestratorContext, service.GetNetworkContainerByOrchestratorContext)
listener.AddHandler(cns.GetAllNetworkContainers, service.GetAllNetworkContainers)
listener.AddHandler(cns.CreateHostNCApipaEndpointPath, service.CreateHostNCApipaEndpoint)
listener.AddHandler(cns.DeleteHostNCApipaEndpointPath, service.DeleteHostNCApipaEndpoint)
listener.AddHandler(cns.RequestIPConfig, NewHandlerFuncWithHistogram(service.RequestIPConfigHandler, HTTPRequestLatency))
listener.AddHandler(cns.RequestIPConfigs, NewHandlerFuncWithHistogram(service.RequestIPConfigsHandler, HTTPRequestLatency))
listener.AddHandler(cns.ReleaseIPConfig, NewHandlerFuncWithHistogram(service.ReleaseIPConfigHandler, HTTPRequestLatency))
listener.AddHandler(cns.ReleaseIPConfigs, NewHandlerFuncWithHistogram(service.ReleaseIPConfigsHandler, HTTPRequestLatency))
// listener.AddHandler(cns.PathDebugIPAddresses, service.HandleDebugIPAddresses)

Check failure on line 1682 in cns/restserver/api_test.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

commentedOutCode: may want to remove commented-out code (gocritic)

Check failure on line 1682 in cns/restserver/api_test.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

commentedOutCode: may want to remove commented-out code (gocritic)
// listener.AddHandler(cns.PathDebugPodContext, service.HandleDebugPodContext)
// listener.AddHandler(cns.PathDebugRestData, service.HandleDebugRestData)
listener.AddHandler(cns.V2Prefix+cns.GetNetworkContainerByOrchestratorContext, service.GetNetworkContainerByOrchestratorContext)
listener.AddHandler(cns.V2Prefix+cns.GetAllNetworkContainers, service.GetAllNetworkContainers)
listener.AddHandler(cns.V2Prefix+cns.CreateHostNCApipaEndpointPath, service.CreateHostNCApipaEndpoint)
}

func startService() error {
// Create the service.
config := common.ServiceConfig{}
Expand Down Expand Up @@ -1730,6 +1751,7 @@ func startService() error {
}

service := service.(*HTTPRestService)
addHandlersToListener(service)

err = service.Start(&config)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cns/restserver/restserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ func (service *HTTPRestService) Init(config *common.ServiceConfig) error {
listener.AddHandler(cns.DeleteNetworkContainer, service.deleteNetworkContainer)
listener.AddHandler(cns.GetInterfaceForContainer, service.getInterfaceForContainer)
listener.AddHandler(cns.SetOrchestratorType, service.setOrchestratorType)
listener.AddHandler(cns.GetNetworkContainerByOrchestratorContext, service.GetNetworkContainerByOrchestratorContext)
listener.AddHandler(cns.GetAllNetworkContainers, service.GetAllNetworkContainers)
// listener.AddHandler(cns.GetNetworkContainerByOrchestratorContext, service.GetNetworkContainerByOrchestratorContext)

Check failure on line 255 in cns/restserver/restserver.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

commentedOutCode: may want to remove commented-out code (gocritic)

Check failure on line 255 in cns/restserver/restserver.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

commentedOutCode: may want to remove commented-out code (gocritic)
// listener.AddHandler(cns.GetAllNetworkContainers, service.GetAllNetworkContainers)
listener.AddHandler(cns.AttachContainerToNetwork, service.attachNetworkContainerToNetwork)
listener.AddHandler(cns.DetachContainerFromNetwork, service.detachNetworkContainerFromNetwork)
listener.AddHandler(cns.CreateHnsNetworkPath, service.createHnsNetwork)
Expand Down Expand Up @@ -289,8 +289,8 @@ func (service *HTTPRestService) Init(config *common.ServiceConfig) error {
listener.AddHandler(cns.V2Prefix+cns.SetOrchestratorType, service.setOrchestratorType)
// listener.AddHandler(cns.V2Prefix+cns.GetNetworkContainerByOrchestratorContext, service.GetNetworkContainerByOrchestratorContext)

Check failure on line 290 in cns/restserver/restserver.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

commentedOutCode: may want to remove commented-out code (gocritic)

Check failure on line 290 in cns/restserver/restserver.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

commentedOutCode: may want to remove commented-out code (gocritic)
// listener.AddHandler(cns.V2Prefix+cns.GetAllNetworkContainers, service.GetAllNetworkContainers)
// listener.AddHandler(cns.V2Prefix+cns.AttachContainerToNetwork, service.attachNetworkContainerToNetwork)
// listener.AddHandler(cns.V2Prefix+cns.DetachContainerFromNetwork, service.detachNetworkContainerFromNetwork)
listener.AddHandler(cns.V2Prefix+cns.AttachContainerToNetwork, service.attachNetworkContainerToNetwork)
listener.AddHandler(cns.V2Prefix+cns.DetachContainerFromNetwork, service.detachNetworkContainerFromNetwork)
// listener.AddHandler(cns.V2Prefix+cns.CreateHnsNetworkPath, service.createHnsNetwork)

Check failure on line 294 in cns/restserver/restserver.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

commentedOutCode: may want to remove commented-out code (gocritic)

Check failure on line 294 in cns/restserver/restserver.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

commentedOutCode: may want to remove commented-out code (gocritic)
// listener.AddHandler(cns.V2Prefix+cns.DeleteHnsNetworkPath, service.deleteHnsNetwork)
listener.AddHandler(cns.V2Prefix+cns.NumberOfCPUCoresPath, service.getNumberOfCPUCores)
Expand Down

0 comments on commit f9668f9

Please sign in to comment.