echoswagger/examples/main_test.go

49 lines
1.4 KiB
Go
Raw Normal View History

/*
* 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 (
"encoding/json"
2018-09-05 14:06:30 +02:00
"io/ioutil"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v4"
2018-09-05 14:06:30 +02:00
"github.com/stretchr/testify/assert"
"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)
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
}