WIP: preserve remaining background task output work
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
type shellOutputTestBroker struct {
|
||||
*fakeChat
|
||||
outputCalls int
|
||||
}
|
||||
|
||||
func (b *shellOutputTestBroker) ShellOutput(context.Context, protocol.ChatShellOutputQuery) (protocol.ChatShellOutputPage, error) {
|
||||
b.outputCalls++
|
||||
return protocol.ChatShellOutputPage{Output: "unexpected"}, nil
|
||||
}
|
||||
|
||||
func TestChatShellOutputRejectsBoundsBeforeRegistryOrProvider(t *testing.T) {
|
||||
store := newOperatorStore(t)
|
||||
broker := &shellOutputTestBroker{fakeChat: scriptedChat()}
|
||||
queries := []protocol.ChatShellOutputQuery{
|
||||
{SessionID: "ses_1", ShellID: "sh_1", Limit: 0},
|
||||
{SessionID: "ses_1", ShellID: "sh_1", Limit: -1},
|
||||
{SessionID: "ses_1", ShellID: "sh_1", Cursor: protocol.ChatShellOutputMaxCursor + 1, Limit: 1},
|
||||
{SessionID: "ses_1", ShellID: "sh_1/../x", Limit: 1},
|
||||
{SessionID: "ses_1", ShellID: "sh_1%2f", Limit: 1},
|
||||
{SessionID: "ses_1", ShellID: "sh_1?cursor=0", Limit: 1},
|
||||
{SessionID: "ses_1", ShellID: "sh_1#fragment", Limit: 1},
|
||||
{SessionID: "ses_1", ShellID: "sh_%ZZ", Limit: 1},
|
||||
{SessionID: "ses_1", ShellID: "sh_" + string(make([]byte, 126)), Limit: 1},
|
||||
}
|
||||
for _, query := range queries {
|
||||
var response protocol.Message
|
||||
handleChatShellOutput(context.Background(), protocol.Message{ChatShellOutputQuery: &query}, broker, store, func(m protocol.Message) error {
|
||||
response = m
|
||||
return nil
|
||||
})
|
||||
if response.Type != protocol.Error {
|
||||
t.Fatalf("query %+v response = %+v", query, response)
|
||||
}
|
||||
}
|
||||
if broker.outputCalls != 0 {
|
||||
t.Fatalf("invalid queries reached provider %d times", broker.outputCalls)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user