mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-25 16:44:01 +08:00
Get Group api test
This commit is contained in:
parent
2a2d9109b0
commit
879ea2309e
1 changed files with 41 additions and 0 deletions
41
group_test.go
Normal file
41
group_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var Groups []models.Group
|
||||
|
||||
func TestGetGroups(t *testing.T) {
|
||||
t.Run("GetGroupValidToken", func(t *testing.T) {
|
||||
response, err := api(t, "", http.MethodGet, "http://localhost:8081/api/groups", "secretkey")
|
||||
assert.Nil(t, err, err)
|
||||
defer response.Body.Close()
|
||||
assert.Equal(t, http.StatusOK, response.StatusCode)
|
||||
|
||||
decoder := json.NewDecoder(response.Body)
|
||||
for decoder.More() {
|
||||
var group models.Group
|
||||
err := decoder.Decode(&group)
|
||||
assert.Nil(t, err, err)
|
||||
Groups = append(Groups, group)
|
||||
}
|
||||
t.Log(Groups)
|
||||
})
|
||||
t.Run("GetGroupInvalidToken", func(t *testing.T) {
|
||||
response, err := api(t, "", http.MethodGet, "http://localhost:8081/api/groups", "badkey")
|
||||
assert.Nil(t, err, err)
|
||||
defer response.Body.Close()
|
||||
var message models.ErrorResponse
|
||||
err = json.NewDecoder(response.Body).Decode(&message)
|
||||
assert.Nil(t, err, err)
|
||||
assert.Equal(t, http.StatusUnauthorized, response.StatusCode)
|
||||
assert.Equal(t, http.StatusUnauthorized, message.Code)
|
||||
assert.Equal(t, "W1R3: You are unauthorized to access this endpoint.", message.Message)
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue