Skip to content

Commit

Permalink
Merge pull request #102 from gravitl/fix-tests
Browse files Browse the repository at this point in the history
CheckInInterval tests working
  • Loading branch information
afeiszli authored Apr 20, 2021
2 parents a0b8e25 + 6204b57 commit ddbeb88
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
4 changes: 2 additions & 2 deletions controllers/networkHttpController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}},
}

Expand Down Expand Up @@ -406,7 +406,7 @@ func updateNetwork(w http.ResponseWriter, r *http.Request) {
{"allowmanualsignup", network.AllowManualSignUp},
{"localrange", network.LocalRange},
{"islocal", network.IsLocal},
{"defaultcheckininterval", network.DefaultCheckInInterval},
{"checkininterval", network.DefaultCheckInInterval},
}},
}

Expand Down
31 changes: 11 additions & 20 deletions test/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -555,38 +551,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 {
Expand Down

0 comments on commit ddbeb88

Please sign in to comment.