From 420bfe0f6b99dc8f671185b62675675f41e2cc58 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Mon, 19 Apr 2021 11:56:57 -0400 Subject: [PATCH 1/2] CheckInInterval tests working --- controllers/networkHttpController.go | 4 ++-- test/group_test.go | 21 ++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/controllers/networkHttpController.go b/controllers/networkHttpController.go index bd6b21c29..73264345b 100644 --- a/controllers/networkHttpController.go +++ b/controllers/networkHttpController.go @@ -234,7 +234,7 @@ func keyUpdate(w http.ResponseWriter, r *http.Request) { {"nodeslastmodified", network.NodesLastModified}, {"networklastmodified", network.NetworkLastModified}, {"allowmanualsignup", network.AllowManualSignUp}, - {"defaultcheckininterval", network.DefaultCheckInInterval}, + {"checkininterval", network.DefaultCheckInInterval}, }}, } @@ -407,7 +407,7 @@ func updateNetwork(w http.ResponseWriter, r *http.Request) { {"allowmanualsignup", network.AllowManualSignUp}, {"localrange", network.LocalRange}, {"islocal", network.IsLocal}, - {"defaultcheckininterval", network.DefaultCheckInInterval}, + {"checkininterval", network.DefaultCheckInInterval}, }}, } diff --git a/test/group_test.go b/test/group_test.go index 497715f8f..1f26000e7 100644 --- a/test/group_test.go +++ b/test/group_test.go @@ -555,38 +555,33 @@ func TestUpdateNetwork(t *testing.T) { assert.Equal(t, network.AllowManualSignUp, returnedNetwork.AllowManualSignUp) }) t.Run("DefaultCheckInterval", func(t *testing.T) { - //value is not updated - t.Skip() type Network struct { - DefaultCheckInInterval int32 + CheckInInterval int32 } var network Network - network.DefaultCheckInInterval = 6000 + network.CheckInInterval = 60 response, err := api(t, network, http.MethodPut, baseURL+"/api/networks/skynet", "secretkey") assert.Nil(t, err, err) assert.Equal(t, http.StatusOK, response.StatusCode) defer response.Body.Close() err = json.NewDecoder(response.Body).Decode(&returnedNetwork) assert.Nil(t, err, err) - assert.Equal(t, network.DefaultCheckInInterval, returnedNetwork.DefaultCheckInInterval) + assert.Equal(t, network.CheckInInterval, returnedNetwork.DefaultCheckInInterval) }) t.Run("DefaultCheckIntervalTooBig", func(t *testing.T) { - //value is not returned in struct --- - t.Skip() - type Network struct { - DefaultCheckInInterval int32 + CheckInInterval int32 } var network Network - network.DefaultCheckInInterval = 100001 + network.CheckInInterval = 100001 response, err := api(t, network, http.MethodPut, baseURL+"/api/networks/skynet", "secretkey") assert.Nil(t, err, err) var message models.ErrorResponse err = json.NewDecoder(response.Body).Decode(&message) assert.Nil(t, err, err) - assert.Equal(t, http.StatusUnprocessableEntity, message.Code) - assert.Equal(t, "W1R3: Field validation for 'DefaultCheckInInterval' failed.", message.Message) - assert.Equal(t, http.StatusUnprocessableEntity, response.StatusCode) + assert.Equal(t, http.StatusBadRequest, message.Code) + assert.Contains(t, message.Message, "Field validation for 'DefaultCheckInInterval' failed") + assert.Equal(t, http.StatusBadRequest, response.StatusCode) }) t.Run("MultipleFields", func(t *testing.T) { type Network struct { From 6204b57f7b2a32c264284b6732c444437a9b902d Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Mon, 19 Apr 2021 13:41:27 -0400 Subject: [PATCH 2/2] update PostDown test --- test/group_test.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/group_test.go b/test/group_test.go index 8f2989910..0ff53b34f 100644 --- a/test/group_test.go +++ b/test/group_test.go @@ -473,22 +473,18 @@ func TestUpdateNetwork(t *testing.T) { assert.Equal(t, network.DefaultPostUp, returnedNetwork.DefaultPostUp) }) t.Run("UpdatePostDown", func(t *testing.T) { - // -------needs fixing ------ - // mismatch in models.Network between struc name and json/bson name - // does not get updated. - type Network struct { - DefaultPreUp string + DefaultPostDown string } var network Network - network.DefaultPreUp = "test string" + network.DefaultPostDown = "test string" response, err := api(t, network, http.MethodPut, baseURL+"/api/networks/skynet", "secretkey") assert.Nil(t, err, err) assert.Equal(t, http.StatusOK, response.StatusCode) defer response.Body.Close() err = json.NewDecoder(response.Body).Decode(&returnedNetwork) assert.Nil(t, err, err) - assert.Equal(t, network.DefaultPreUp, returnedNetwork.DefaultPostDown) + assert.Equal(t, network.DefaultPostDown, returnedNetwork.DefaultPostDown) }) t.Run("UpdateKeepAlive", func(t *testing.T) { type Network struct {