CodeSampleX

샘플

google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.ResourceInfo

검증된 샘플 — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.ResourceInfo. go 1.26 · linux alpine/x64 · docker에서…

sha256:177cf900f143e9336b8adf199d3539df476e050512ad96f6198abedbdd9546a3

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go

검증 실행 환경

환경 컨트랙트 단계 실행일
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-27

케이스

HOW
목표
verify google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
패키지
심벌
  • google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo
생성일
2026-08-27T11:54:47Z

컨트랙트

  1. ResourceInfo correctly stores and returns ResourceType, ResourceName, Owner, and Description fields
  2. Getters return safe empty string defaults when called on a nil ResourceInfo pointer
  3. ResourceInfo correctly serializes to and deserializes from protocol buffer binary format
  4. Reset clears all fields of a ResourceInfo instance to their zero values
  5. ProtoReflect returns a valid Message descriptor matching google.rpc.ResourceInfo full name

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:0203997b94c29258593a12ddd9b006871087ad1e6e499b01aaf4612f65515d4d","contract":["ResourceInfo correctly stores and returns ResourceType, ResourceName, Owner, and Description fields","Getters return safe empty string defaults when called on a nil ResourceInfo pointer","ResourceInfo correctly serializes to and deserializes from protocol buffer binary format","Reset clears all fields of a ResourceInfo instance to their zero values","ProtoReflect returns a valid Message descriptor matching google.rpc.ResourceInfo full name"],"goal":"verify google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9","symbols":["google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.25.0

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9
	google.golang.org/protobuf v1.36.12
)
go.sum
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
main.go
package main

import (
	"fmt"

	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/protobuf/proto"
)

// CreateResourceInfo creates a ResourceInfo instance with the given details.
func CreateResourceInfo(resourceType, resourceName, owner, description string) *errdetails.ResourceInfo {
	return &errdetails.ResourceInfo{
		ResourceType: resourceType,
		ResourceName: resourceName,
		Owner:        owner,
		Description:  description,
	}
}

// MarshalResourceInfo serializes a ResourceInfo proto message to binary.
func MarshalResourceInfo(info *errdetails.ResourceInfo) ([]byte, error) {
	return proto.Marshal(info)
}

// UnmarshalResourceInfo deserializes binary data into a ResourceInfo proto message.
func UnmarshalResourceInfo(data []byte) (*errdetails.ResourceInfo, error) {
	var info errdetails.ResourceInfo
	if err := proto.Unmarshal(data, &info); err != nil {
		return nil, err
	}
	return &info, nil
}

func main() {
	info := CreateResourceInfo(
		"type.googleapis.com/example.Database",
		"projects/example-project/databases/db-1",
		"admin@example.com",
		"Database resource quota exceeded",
	)

	fmt.Printf("Resource Type: %s\n", info.GetResourceType())
	fmt.Printf("Resource Name: %s\n", info.GetResourceName())
	fmt.Printf("Owner: %s\n", info.GetOwner())
	fmt.Printf("Description: %s\n", info.GetDescription())

	data, err := MarshalResourceInfo(info)
	if err != nil {
		panic(err)
	}

	decoded, err := UnmarshalResourceInfo(data)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Decoded Resource: %s\n", decoded.GetResourceName())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/reflect/protoreflect"
)

func main() {
	// Assertion 1: ResourceInfo correctly stores and returns ResourceType, ResourceName, Owner, and Description fields
	res := &errdetails.ResourceInfo{
		ResourceType: "storage.googleapis.com/Bucket",
		ResourceName: "projects/sample-project/buckets/data-store",
		Owner:        "service-admin",
		Description:  "Sample bucket resource",
	}

	if got := res.GetResourceType(); got != "storage.googleapis.com/Bucket" {
		fmt.Fprintf(os.Stderr, "FAIL: GetResourceType mismatch: got %q, want %q\n", got, "storage.googleapis.com/Bucket")
		os.Exit(1)
	}
	if got := res.GetResourceName(); got != "projects/sample-project/buckets/data-store" {
		fmt.Fprintf(os.Stderr, "FAIL: GetResourceName mismatch: got %q, want %q\n", got, "projects/sample-project/buckets/data-store")
		os.Exit(1)
	}
	if got := res.GetOwner(); got != "service-admin" {
		fmt.Fprintf(os.Stderr, "FAIL: GetOwner mismatch: got %q, want %q\n", got, "service-admin")
		os.Exit(1)
	}
	if got := res.GetDescription(); got != "Sample bucket resource" {
		fmt.Fprintf(os.Stderr, "FAIL: GetDescription mismatch: got %q, want %q\n", got, "Sample bucket resource")
		os.Exit(1)
	}

	// Assertion 2: Getters return safe empty string defaults when called on a nil ResourceInfo pointer
	var nilRes *errdetails.ResourceInfo
	if got := nilRes.GetResourceType(); got != "" {
		fmt.Fprintf(os.Stderr, "FAIL: nil GetResourceType expected empty string, got %q\n", got)
		os.Exit(1)
	}
	if got := nilRes.GetResourceName(); got != "" {
		fmt.Fprintf(os.Stderr, "FAIL: nil GetResourceName expected empty string, got %q\n", got)
		os.Exit(1)
	}
	if got := nilRes.GetOwner(); got != "" {
		fmt.Fprintf(os.Stderr, "FAIL: nil GetOwner expected empty string, got %q\n", got)
		os.Exit(1)
	}
	if got := nilRes.GetDescription(); got != "" {
		fmt.Fprintf(os.Stderr, "FAIL: nil GetDescription expected empty string, got %q\n", got)
		os.Exit(1)
	}

	// Assertion 3: ResourceInfo correctly serializes to and deserializes from protocol buffer binary format
	data, err := proto.Marshal(res)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: proto.Marshal failed: %v\n", err)
		os.Exit(1)
	}
	if len(data) == 0 {
		fmt.Fprintf(os.Stderr, "FAIL: marshaled proto data is empty\n")
		os.Exit(1)
	}

	var unmarshaled errdetails.ResourceInfo
	if err := proto.Unmarshal(data, &unmarshaled); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: proto.Unmarshal failed: %v\n", err)
		os.Exit(1)
	}
	if !proto.Equal(res, &unmarshaled) {
		fmt.Fprintf(os.Stderr, "FAIL: unmarshaled proto does not equal original\n")
		os.Exit(1)
	}

	// Assertion 4: Reset clears all fields of a ResourceInfo instance to their zero values
	copyRes := &errdetails.ResourceInfo{
		ResourceType: "compute.googleapis.com/Instance",
		ResourceName: "projects/sample-project/zones/us-central1-a/instances/worker-1",
		Owner:        "ops-team",
		Description:  "Compute engine instance",
	}
	copyRes.Reset()
	if copyRes.GetResourceType() != "" || copyRes.GetResourceName() != "" || copyRes.GetOwner() != "" || copyRes.GetDescription() != "" {
		fmt.Fprintf(os.Stderr, "FAIL: Reset failed to clear all fields\n")
		os.Exit(1)
	}

	// Assertion 5: ProtoReflect returns a valid Message descriptor matching google.rpc.ResourceInfo full name
	msg := res.ProtoReflect()
	descriptor := msg.Descriptor()
	if string(descriptor.FullName()) != "google.rpc.ResourceInfo" {
		fmt.Fprintf(os.Stderr, "FAIL: Descriptor FullName mismatch: got %q, want %q\n", descriptor.FullName(), "google.rpc.ResourceInfo")
		os.Exit(1)
	}
	resTypeField := descriptor.Fields().ByName(protoreflect.Name("resource_type"))
	if resTypeField == nil {
		fmt.Fprintf(os.Stderr, "FAIL: field descriptor for resource_type not found\n")
		os.Exit(1)
	}

	fmt.Println("PASS: google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo contract verified")
}

오리진 시더

익명