mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-07-27 01:03:34 +00:00
* Call OAS feeder * Don't call old OAS code * Rework calls * Work on it * Put back rules * Make it compile * start thinking of test * Compiles * Save * Fixes * Save * Fixing * Trying to fake conn * add timeout * Test timeout * Fix tests * Only build OAS for HTTP entries * Remove some dead code * Adding SampleIDs * Cosmetics * lint * Revert rename * Sample ID for content * Cleanuo * Add more sample IDs * Checking hypothesis * Move assignment place a bit * Cosmetics * Update test.yml Co-authored-by: undera <undera@undera-old-desktop.home> Co-authored-by: Igor Gov <iggvrv@gmail.com>
70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
package controllers
|
|
|
|
import (
|
|
"bytes"
|
|
basenine "github.com/up9inc/basenine/client/go"
|
|
"net"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/up9inc/mizu/agent/pkg/dependency"
|
|
"github.com/up9inc/mizu/agent/pkg/oas"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestGetOASServers(t *testing.T) {
|
|
recorder, c := getRecorderAndContext()
|
|
|
|
GetOASServers(c)
|
|
t.Logf("Written body: %s", recorder.Body.String())
|
|
}
|
|
|
|
func TestGetOASAllSpecs(t *testing.T) {
|
|
recorder, c := getRecorderAndContext()
|
|
|
|
GetOASAllSpecs(c)
|
|
t.Logf("Written body: %s", recorder.Body.String())
|
|
}
|
|
|
|
func TestGetOASSpec(t *testing.T) {
|
|
recorder, c := getRecorderAndContext()
|
|
|
|
c.Params = []gin.Param{{Key: "id", Value: "some"}}
|
|
|
|
GetOASSpec(c)
|
|
t.Logf("Written body: %s", recorder.Body.String())
|
|
}
|
|
|
|
type fakeConn struct {
|
|
sendBuffer *bytes.Buffer
|
|
receiveBuffer *bytes.Buffer
|
|
}
|
|
|
|
func (f fakeConn) Read(p []byte) (int, error) { return f.sendBuffer.Read(p) }
|
|
func (f fakeConn) Write(p []byte) (int, error) { return f.receiveBuffer.Write(p) }
|
|
func (fakeConn) Close() error { return nil }
|
|
func (fakeConn) LocalAddr() net.Addr { return nil }
|
|
func (fakeConn) RemoteAddr() net.Addr { return nil }
|
|
func (fakeConn) SetDeadline(t time.Time) error { return nil }
|
|
func (fakeConn) SetReadDeadline(t time.Time) error { return nil }
|
|
func (fakeConn) SetWriteDeadline(t time.Time) error { return nil }
|
|
|
|
func getRecorderAndContext() (*httptest.ResponseRecorder, *gin.Context) {
|
|
dummyConn := new(basenine.Connection)
|
|
dummyConn.Conn = fakeConn{
|
|
sendBuffer: bytes.NewBufferString("\n"),
|
|
receiveBuffer: bytes.NewBufferString("\n"),
|
|
}
|
|
dependency.RegisterGenerator(dependency.OasGeneratorDependency, func() interface{} {
|
|
return oas.GetDefaultOasGeneratorInstance(dummyConn)
|
|
})
|
|
|
|
recorder := httptest.NewRecorder()
|
|
c, _ := gin.CreateTestContext(recorder)
|
|
oas.GetDefaultOasGeneratorInstance(dummyConn).Start()
|
|
oas.GetDefaultOasGeneratorInstance(dummyConn).GetServiceSpecs().Store("some", oas.NewGen("some"))
|
|
return recorder, c
|
|
}
|