blob: b12ce5c7fac15ef6997ffddc810c6f717fbb47ee [file] [edit]
// Copyright 2026 Google LLC
//
// 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 casmsg
import (
"testing"
bspb "google.golang.org/genproto/googleapis/bytestream"
_ "github.com/bazelbuild/rsclient/internal/pkg/testsetup"
)
// TestByteStreamAssembler_StickyNames verifies the restoration of missing
// ResourceNames in Bytestream Write sequences.
func TestByteStreamAssembler_StickyNames(t *testing.T) {
assembler := NewByteStreamAssembler()
// 1. First chunk with name: name should be remembered.
raw1 := &RawWriteRequest{
StreamID: 1,
Req: &bspb.WriteRequest{ResourceName: "sticky-name", Data: []byte("part1")},
}
got1, ok := assembler.Assemble(raw1)
if !ok || got1.ResourceName != "sticky-name" {
t.Errorf("First chunk failed: ok=%v, name=%q", ok, got1.GetResourceName())
}
// 2. Second chunk without name: name should be restored from the first chunk.
raw2 := &RawWriteRequest{
StreamID: 1,
Req: &bspb.WriteRequest{Data: []byte("part2")},
}
got2, ok := assembler.Assemble(raw2)
if !ok || got2.ResourceName != "sticky-name" {
t.Errorf("Second chunk failed: ok=%v, name=%q", ok, got2.GetResourceName())
}
}