CasaOS/route/v1/samba_test.go
link cee34ec1c2
0.3.5 (#451)
* initial completion of the sharing function

* Adjusting multi-partition disk mounts

* Add file sharing function

* update usb auto mount shell

* update samba config

* add umount disk function

* update change log

* update usb auto mount \

* update usb auto mount

* Update periodical.go
2022-08-15 11:37:21 +08:00

74 lines
2 KiB
Go

/*
* @Author: LinkLeong link@icewhale.org
* @Date: 2022-08-02 15:10:56
* @LastEditors: LinkLeong
* @LastEditTime: 2022-08-02 16:58:42
* @FilePath: /CasaOS/route/v1/samba_test.go
* @Description:
* @Website: https://www.casaos.io
* Copyright (c) 2022 by icewhale, All Rights Reserved.
*/
package v1
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)
func performRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
req, _ := http.NewRequest(method, path, nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
return w
}
// func TestHelloWorld(t *testing.T) {
// // Build our expected body
// body := gin.H{
// "hello": "world",
// }
// // Grab our router
// router := "SetupRouter()"
// // Perform a GET request with that handler.
// w := performRequest(router, "GET", "/")
// // Assert we encoded correctly,
// // the request gives a 200
// assert.Equal(t, http.StatusOK, w.Code)
// // Convert the JSON response to a map
// var response map[string]string
// err := json.Unmarshal([]byte(w.Body.String()), &response)
// // Grab the value & whether or not it exists
// value, exists := response["hello"]
// // Make some assertions on the correctness of the response.
// assert.Nil(t, err)
// assert.True(t, exists)
// assert.Equal(t, body["hello"], value)
// }
func TestGetSambaSharesList(t *testing.T) {
gin.SetMode(gin.TestMode)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
executeWithContext := func() *httptest.ResponseRecorder {
response := httptest.NewRecorder()
con, ginEngine := gin.CreateTestContext(response)
requestUrl := "/v1/samba/shares"
httpRequest, _ := http.NewRequest("GET", requestUrl, nil)
GetSambaSharesList(con)
ginEngine.ServeHTTP(response, httpRequest)
return response
}
t.Run("Happy", func(t *testing.T) {
res := executeWithContext()
assert.Equal(t, http.StatusOK, res.Code)
})
}