Skip to content

Commit

Permalink
fix: add a helper test func for default value
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Dec 6, 2023
1 parent 928cdb1 commit 82f7fc4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
19 changes: 9 additions & 10 deletions api/v1/bandwidth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import (
func (s *APITestSuite) TestBandwidthStartStop() {
t := s.T()

reqBody := api.BandwidthStartRequest{
NetworkInterfaceName: s.ifaceName,
Limit: 100,
}
jsonBody, err := json.Marshal(reqBody)
jsonBody, err := json.Marshal(s.getDefaultBandwidthStartRequest())
require.NoError(t, err)

req, err := http.NewRequest(http.MethodPost, "/api/v1/bandwidth/start", bytes.NewReader(jsonBody))
Expand Down Expand Up @@ -49,11 +45,7 @@ func (s *APITestSuite) TestBandwidthStatus() {
t.Fatalf("unexpected service status: %s", slug)
}

reqBody := api.BandwidthStartRequest{
NetworkInterfaceName: s.ifaceName,
Limit: 100,
}
jsonBody, err := json.Marshal(reqBody)
jsonBody, err := json.Marshal(s.getDefaultBandwidthStartRequest())
require.NoError(t, err)

req, err := http.NewRequest(http.MethodPost, "/api/v1/bandwidth/start", bytes.NewReader(jsonBody))
Expand All @@ -73,3 +65,10 @@ func (s *APITestSuite) TestBandwidthStatus() {
require.NoError(t, err)
assert.Equal(t, api.SlugServiceNotReady, slug)
}

func (s *APITestSuite) getDefaultBandwidthStartRequest() api.BandwidthStartRequest {
return api.BandwidthStartRequest{
NetworkInterfaceName: s.ifaceName,
Limit: 100,
}
}
22 changes: 10 additions & 12 deletions api/v1/latency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ import (
func (s *APITestSuite) TestLatencyStartStop() {
t := s.T()

reqBody := api.LatencyStartRequest{
NetworkInterfaceName: s.ifaceName,
Latency: 100,
Jitter: 50,
}
jsonBody, err := json.Marshal(reqBody)
jsonBody, err := json.Marshal(s.getDefaultLatencyStartRequest())
require.NoError(t, err)

req, err := http.NewRequest(http.MethodPost, "/api/v1/latency/start", bytes.NewReader(jsonBody))
Expand Down Expand Up @@ -50,12 +45,7 @@ func (s *APITestSuite) TestLatencyStatus() {
t.Fatalf("unexpected service status: %s", slug)
}

reqBody := api.LatencyStartRequest{
NetworkInterfaceName: s.ifaceName,
Latency: 100,
Jitter: 50,
}
jsonBody, err := json.Marshal(reqBody)
jsonBody, err := json.Marshal(s.getDefaultLatencyStartRequest())
require.NoError(t, err)

req, err := http.NewRequest(http.MethodPost, "/api/v1/latency/start", bytes.NewReader(jsonBody))
Expand All @@ -79,3 +69,11 @@ func (s *APITestSuite) TestLatencyStatus() {
require.NoError(t, err)
assert.Equal(t, api.SlugServiceNotReady, slug)
}

func (s *APITestSuite) getDefaultLatencyStartRequest() api.LatencyStartRequest {
return api.LatencyStartRequest{
NetworkInterfaceName: s.ifaceName,
Latency: 100,
Jitter: 50,
}
}
19 changes: 9 additions & 10 deletions api/v1/packetloss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import (
func (s *APITestSuite) TestPacketlossStartStop() {
t := s.T()

reqBody := api.PacketLossStartRequest{
NetworkInterfaceName: s.ifaceName,
PacketLossRate: 10,
}
jsonBody, err := json.Marshal(reqBody)
jsonBody, err := json.Marshal(s.getDefaultPacketLossStartRequest())
require.NoError(t, err)

req, err := http.NewRequest(http.MethodPost, "/api/v1/packetloss/start", bytes.NewReader(jsonBody))
Expand Down Expand Up @@ -49,11 +45,7 @@ func (s *APITestSuite) TestPacketlossStatus() {
t.Fatalf("unexpected service status: %s", slug)
}

reqBody := api.PacketLossStartRequest{
NetworkInterfaceName: s.ifaceName,
PacketLossRate: 10,
}
jsonBody, err := json.Marshal(reqBody)
jsonBody, err := json.Marshal(s.getDefaultPacketLossStartRequest())
require.NoError(t, err)

req, err := http.NewRequest(http.MethodPost, "/api/v1/packetloss/start", bytes.NewReader(jsonBody))
Expand All @@ -77,3 +69,10 @@ func (s *APITestSuite) TestPacketlossStatus() {
require.NoError(t, err)
assert.Equal(t, api.SlugServiceNotReady, slug)
}

func (s *APITestSuite) getDefaultPacketLossStartRequest() api.PacketLossStartRequest {
return api.PacketLossStartRequest{
NetworkInterfaceName: s.ifaceName,
PacketLossRate: 10,
}
}

0 comments on commit 82f7fc4

Please sign in to comment.