mirror of
https://codeberg.org/crowci/crow.git
synced 2025-06-07 01:21:05 +03:00
- `mockery` can now be run in one call instead of multiple ones - Use the recommended "packages" approach which will be the new default moving forward - Enforce consistent naming of mock files - Remove warnings when invoking `mockery` - Get rid of *many* linter warnings 🎉️ Reviewed-on: https://codeberg.org/crowci/crow/pulls/38 Co-authored-by: pat-s <patrick.schratz@gmail.com> Co-committed-by: pat-s <patrick.schratz@gmail.com>
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
// Copyright 2019 Woodpecker Authors
|
|
//
|
|
// 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.
|
|
|
|
package log_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"codeberg.org/crowci/crow/v3/pipeline/log"
|
|
"codeberg.org/crowci/crow/v3/pipeline/rpc"
|
|
rpc_mocks "codeberg.org/crowci/crow/v3/pipeline/rpc/mocks"
|
|
)
|
|
|
|
func TestLineWriter(t *testing.T) {
|
|
peer := new(rpc_mocks.MockPeer)
|
|
peer.On("EnqueueLog", mock.Anything)
|
|
|
|
secrets := []string{"world"}
|
|
lw := log.NewLineWriter(peer, "e9ea76a5-44a1-4059-9c4a-6956c478b26d", secrets...)
|
|
|
|
_, err := lw.Write([]byte("hello world\n"))
|
|
assert.NoError(t, err)
|
|
_, err = lw.Write([]byte("the previous line had no newline at the end"))
|
|
assert.NoError(t, err)
|
|
|
|
peer.AssertCalled(t, "EnqueueLog", &rpc.LogEntry{
|
|
StepUUID: "e9ea76a5-44a1-4059-9c4a-6956c478b26d",
|
|
Time: 0,
|
|
Type: rpc.LogEntryStdout,
|
|
Line: 0,
|
|
Data: []byte("hello ********"),
|
|
})
|
|
|
|
peer.AssertCalled(t, "EnqueueLog", &rpc.LogEntry{
|
|
StepUUID: "e9ea76a5-44a1-4059-9c4a-6956c478b26d",
|
|
Time: 0,
|
|
Type: rpc.LogEntryStdout,
|
|
Line: 1,
|
|
Data: []byte("the previous line had no newline at the end"),
|
|
})
|
|
|
|
peer.AssertExpectations(t)
|
|
}
|