Skip to content

Commit

Permalink
correcting go tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vhowdhur committed Oct 18, 2023
1 parent 6e84b47 commit 55cd19b
Show file tree
Hide file tree
Showing 10 changed files with 12,480 additions and 12,489 deletions.
2,706 changes: 1,353 additions & 1,353 deletions gosnappi/generated_invalid_format_test.go

Large diffs are not rendered by default.

2,706 changes: 1,353 additions & 1,353 deletions gosnappi/generated_invalid_key_test.go

Large diffs are not rendered by default.

1,884 changes: 942 additions & 942 deletions gosnappi/generated_required_test.go

Large diffs are not rendered by default.

8,547 changes: 4,273 additions & 4,274 deletions gosnappi/generated_test.go

Large diffs are not rendered by default.

8,841 changes: 4,420 additions & 4,421 deletions gosnappi/generated_validate_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gosnappi/gosnappiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestSnappiServer(t *testing.T) {
api.NewHttpTransport().SetLocation("http://127.0.0.1:50071")
config := config1(api)
state, err := api.SetConfig(config)
data, _ := state.ToJson()
data, _ := state.Marshaller().ToJson()
fmt.Println("state : ", data)
fmt.Println("err: ", err)
}
3 changes: 1 addition & 2 deletions gosnappi/ingress_egress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
)

func TestIngressEgress(t *testing.T) {
api := gosnappi.NewApi()
config := api.NewConfig()
config := gosnappi.NewConfig()
port1 := config.Ports().Add()
port2 := config.Ports().Add()
port1.SetName("port1")
Expand Down
12 changes: 6 additions & 6 deletions gosnappi/mock_grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ func (s *server) GetMetrics(ctx context.Context, req *otg.GetMetricsRequest) (*o
if !res {
resp = nil
errObj := NewError()
errObj.Msg().Code = &errCode
errObj.Msg().Errors = []string{"requested flow is not available in configured flows"}
_ = errObj.SetCode(errCode)
_ = errObj.SetErrors([]string{"requested flow is not available in configured flows"})
err = errObj
} else if len(metricsDisabledFlows) > 0 {
resp = nil
errObj := NewError()
errObj.Msg().Code = &errCode
errObj.Msg().Errors = []string{"metrics not enabled for all the flows"}
_ = errObj.SetCode(errCode)
_ = errObj.SetErrors([]string{"metrics not enabled for all the flows"})
err = errObj
} else {
resp = &otg.GetMetricsResponse{
Expand All @@ -176,8 +176,8 @@ func (s *server) GetMetrics(ctx context.Context, req *otg.GetMetricsRequest) (*o
resp = nil
resp = nil
errObj := NewError()
errObj.Msg().Code = &errCode
errObj.Msg().Errors = []string{"requested port is not available in configured ports"}
_ = errObj.SetCode(errCode)
_ = errObj.SetErrors([]string{"requested port is not available in configured ports"})
err = errObj
} else {
resp = &otg.GetMetricsResponse{
Expand Down
46 changes: 23 additions & 23 deletions gosnappi/mock_httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type HttpServer struct {
serverLocation string
Api GosnappiApi
Api Api
Config Config
}

Expand All @@ -19,26 +19,26 @@ var (
func StartMockHttpServer(location string) {
httpServer.serverLocation = location
httpServer.Api = NewApi()
httpServer.Config = httpServer.Api.NewConfig()
httpServer.Config = NewConfig()

http.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPost:
body, _ := ioutil.ReadAll(r.Body)
httpServer.Config.FromJson(string(body))
response := httpServer.Api.NewSetConfigResponse()
httpServer.Config.Marshaller().FromJson(string(body))
response := NewSetConfigResponse()
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
resp, _ := response.Warning().ToJson()
resp, _ := response.Warning().Marshaller().ToJson()
w.Write([]byte(resp))
case http.MethodGet:
// config := httpServer.Config
response := httpServer.Api.NewGetConfigResponse()
httpServerConfig, _ := httpServer.Config.ToJson()
response.Config().FromJson(httpServerConfig)
response := NewGetConfigResponse()
httpServerConfig, _ := httpServer.Config.Marshaller().ToJson()
response.Config().Marshaller().FromJson(httpServerConfig)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
resp, _ := response.Config().ToJson()
resp, _ := response.Config().Marshaller().ToJson()
w.Write([]byte(resp))
}
})
Expand All @@ -48,44 +48,44 @@ func StartMockHttpServer(location string) {
switch r.Method {
case http.MethodPost:
body, _ := ioutil.ReadAll(r.Body)
metricsReq := httpServer.Api.NewMetricsRequest()
metricsReq.FromJson(string(body))
metricsReq := NewMetricsRequest()
metricsReq.Marshaller().FromJson(string(body))
if metricsReq.Choice() == MetricsRequestChoice.FLOW {
flow_responses := httpServer.Api.NewGetMetricsResponse().MetricsResponse()
flow_responses := NewGetMetricsResponse().MetricsResponse()
for _, flow_name := range metricsReq.Flow().FlowNames() {
flow_rsp := flow_responses.FlowMetrics().Add()
flow_rsp.SetName(flow_name)
flow_rsp.SetBytesTx(1000)
flow_rsp.SetBytesRx(1000)
}
response := httpServer.Api.NewGetMetricsResponse().MetricsResponse()
flow_resp, _ := flow_responses.ToJson()
response.FromJson(flow_resp)
response := NewGetMetricsResponse().MetricsResponse()
flow_resp, _ := flow_responses.Marshaller().ToJson()
response.Marshaller().FromJson(flow_resp)
w.WriteHeader(http.StatusOK)
w.Write([]byte(flow_resp))
} else if metricsReq.Choice() == MetricsRequestChoice.PORT {
port_response := httpServer.Api.NewGetMetricsResponse().MetricsResponse()
port_response := NewGetMetricsResponse().MetricsResponse()
for _, port_name := range metricsReq.Port().PortNames() {
port_rsp := port_response.PortMetrics().Add()
port_rsp.SetName(port_name)
port_rsp.SetBytesTx(2000)
port_rsp.SetBytesRx(2000)
}
response := httpServer.Api.NewGetMetricsResponse().MetricsResponse()
port_resp, _ := port_response.ToJson()
response.FromJson(port_resp)
response := NewGetMetricsResponse().MetricsResponse()
port_resp, _ := port_response.Marshaller().ToJson()
response.Marshaller().FromJson(port_resp)
w.WriteHeader(http.StatusOK)
w.Write([]byte(port_resp))
} else if metricsReq.Choice() == MetricsRequestChoice.BGPV4 {
bgpv4_response := httpServer.Api.NewGetMetricsResponse().MetricsResponse()
bgpv4_response := NewGetMetricsResponse().MetricsResponse()
for _, bgpv4_name := range metricsReq.Bgpv4().PeerNames() {
bgpv4_rsp := bgpv4_response.Bgpv4Metrics().Add()
bgpv4_rsp.SetName(bgpv4_name)
bgpv4_rsp.SetRoutesAdvertised(80)
}
response := httpServer.Api.NewGetMetricsResponse().MetricsResponse()
bgpv4_resp, _ := bgpv4_response.ToJson()
response.FromJson(bgpv4_resp)
response := NewGetMetricsResponse().MetricsResponse()
bgpv4_resp, _ := bgpv4_response.Marshaller().ToJson()
response.Marshaller().FromJson(bgpv4_resp)
w.WriteHeader(http.StatusOK)
w.Write([]byte(bgpv4_resp))
}
Expand Down
Loading

0 comments on commit 55cd19b

Please sign in to comment.