| // 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" |
| |
| "github.com/bazelbuild/remote-apis-sdks/go/pkg/digest" |
| |
| _ "github.com/bazelbuild/rsclient/internal/pkg/testsetup" |
| ) |
| |
| // TestResourceInfo_Format verifies that CAS resource names are formatted |
| // correctly for both simple and upload paths. |
| func TestResourceInfo_Format(t *testing.T) { |
| hash := "8b9e17429e7b6e436933aeb13d4eff0a40842b6164bbf4a9c4239774f029b2fe" |
| d, err := digest.New(hash, 123) |
| if err != nil { |
| t.Fatalf("digest.New failed: %v", err) |
| } |
| |
| tests := []struct { |
| name string |
| info ResourceInfo |
| expected string |
| }{ |
| { |
| name: "full upload path", |
| info: ResourceInfo{ |
| Digest: d, |
| Instance: "my-instance", |
| UUID: "my-uuid", |
| }, |
| expected: "my-instance/uploads/my-uuid/blobs/" + hash + "/123", |
| }, |
| { |
| name: "blob path with instance", |
| info: ResourceInfo{ |
| Digest: d, |
| Instance: "my-instance", |
| }, |
| expected: "my-instance/blobs/" + hash + "/123", |
| }, |
| } |
| |
| for _, tc := range tests { |
| t.Run(tc.name, func(t *testing.T) { |
| got := tc.info.Format() |
| if got != tc.expected { |
| t.Errorf("Format() = %q, want %q", got, tc.expected) |
| } |
| }) |
| } |
| } |