fix: 编码 OpenSandbox assignment metadata
This commit is contained in:
@@ -31,7 +31,8 @@ func (f *fakeLifecycle) GetSandbox(_ context.Context, id string) (*opensandbox.S
|
||||
return &item, nil
|
||||
}
|
||||
}
|
||||
return &opensandbox.SandboxInfo{ID: id, Metadata: map[string]string{"ci.ddupan.top/spiffe-id": assignment().Identity.SPIFFEID}}, nil
|
||||
metadata, _ := encodeAnnotations(map[string]string{"ci.ddupan.top/spiffe-id": assignment().Identity.SPIFFEID})
|
||||
return &opensandbox.SandboxInfo{ID: id, Metadata: metadata}, nil
|
||||
}
|
||||
func (f *fakeLifecycle) PatchSandboxMetadata(_ context.Context, id string, patch opensandbox.MetadataPatch) (*opensandbox.SandboxInfo, error) {
|
||||
for index := range f.items {
|
||||
@@ -95,6 +96,32 @@ func TestCreateUsesPoolAndPersistsRecoveryMetadata(t *testing.T) {
|
||||
if lifecycle.created.Env["CI_RUNNER_CAPABILITY"] != "capability" {
|
||||
t.Fatalf("environment = %#v", lifecycle.created.Env)
|
||||
}
|
||||
annotations, err := decodeAnnotations(lifecycle.created.Metadata)
|
||||
if err != nil || annotations["ci.ddupan.top/repository"] != "owner/repo" || annotations["ci.ddupan.top/spiffe-id"] != assignment().Identity.SPIFFEID {
|
||||
t.Fatalf("annotations=%#v err=%v", annotations, err)
|
||||
}
|
||||
for _, value := range lifecycle.created.Metadata {
|
||||
if len(value) > metadataValueLimit {
|
||||
t.Fatalf("metadata value exceeds %d characters: %q", metadataValueLimit, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnnotationMetadataRoundTripPreservesSlashValues(t *testing.T) {
|
||||
want := taskworker.BackendMetadata(assignment()).Annotations
|
||||
encoded, err := encodeAnnotations(want)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := decodeAnnotations(encoded)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for key, value := range want {
|
||||
if got[key] != value {
|
||||
t.Fatalf("%s=%q, want %q", key, got[key], value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBindIdentityVerifiesPersistedMetadata(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user