2019-12-18 11:26:20 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Alex aka mailoman <alex@webz.asia>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* @author Alex aka mailoman <alex@webz.asia>
|
|
|
|
* @copyright Copyright (c) 2019 Alex aka mailoman <alex@webz.asia>
|
|
|
|
* @since 18.12.2019
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-09-05 14:06:30 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-05-12 17:10:04 +02:00
|
|
|
"encoding/json"
|
2018-09-05 14:06:30 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
2019-12-18 11:26:20 +01:00
|
|
|
"github.com/labstack/echo/v4"
|
2018-09-05 14:06:30 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-12-18 11:26:20 +01:00
|
|
|
|
2022-08-25 09:31:53 +02:00
|
|
|
"git.webz.asia/echo-go/echoswagger"
|
2018-09-05 14:06:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(t *testing.T) {
|
|
|
|
e := initServer()
|
|
|
|
req := httptest.NewRequest(echo.GET, "/doc/swagger.json", nil)
|
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
c := e.Echo().NewContext(req, rec)
|
|
|
|
b, err := ioutil.ReadFile("./swagger.json")
|
|
|
|
assert.Nil(t, err)
|
2019-05-12 17:10:04 +02:00
|
|
|
s, err := e.(*echoswagger.Root).GetSpec(c, "/doc")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
rs, err := json.Marshal(s)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.JSONEq(t, string(b), string(rs))
|
2018-09-05 14:06:30 +02:00
|
|
|
}
|