Skip to content

Commit

Permalink
feat(package): add ClonedFrom field to PackageMetadata (#527)
Browse files Browse the repository at this point in the history
* Add ClonedFrom to PackageMetadata

We recently exposed the source repo for e.g. Compute Starter Kits via
the `cloned_from` key in the PackageMetadata resource in the API. This
makes it programmatically accessible.

* Incorporate feedback from PR

* Sort struct fields
* Run `make fix-fixtures FASTLY_TEST_SERVICE_ID=sSsCewrlNQiMzZHiqD8Xr0`

* Update tests

* Update fixtures

This updates the valid.tar.gz package to the current Rust empty Starter
Kit and updates fixtures to match by following the steps in TESTING.md.
  • Loading branch information
jsocol authored May 28, 2024
1 parent f2be363 commit 9804362
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 55 deletions.
1 change: 1 addition & 0 deletions fastly/compute_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Package struct {
// the raw data is returned as a json sub-block.
type PackageMetadata struct {
Authors []string `mapstructure:"authors"`
ClonedFrom *string `mapstructure:"cloned_from"`
Description *string `mapstructure:"description"`
FilesHash *string `mapstructure:"files_hash"`
HashSum *string `mapstructure:"hashsum"`
Expand Down
21 changes: 14 additions & 7 deletions fastly/compute_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ func TestClient_Package(t *testing.T) {

testData := Package{
Metadata: &PackageMetadata{
Description: ToPointer("Default package template used by the Fastly CLI for Rust-based Compute@Edge projects."),
HashSum: ToPointer("f99485bd301e23f028474d26d398da525de17a372ae9e7026891d7f85361d2540d14b3b091929c3f170eade573595e20b3405a9e29651ede59915f2e1652f616"),
ClonedFrom: ToPointer("https://github.com/fastly/compute-starter-kit-rust-empty"),
Description: ToPointer("An empty starter kit project template."),
FilesHash: ToPointer("75ff1cf4d953ff2242bb38e4a01b04503622baf4b7dc540256f4dd5fc89df5aed7fea115adab0b71caa79f6483bb846ac0d4f4f937885fb03ee35d2dfafba6f3"),
HashSum: ToPointer("ecc068efcd4071d36d6460152dcc50461b649f01f28589917540a69d33e9b1477decb5f5a9a2f6c269d83a13827502c1fe1f2efc3bdd6beadaabd23e22eb84fd"),
Language: ToPointer("rust"),
Name: ToPointer("wasm-test"),
Size: ToPointer(int64(2015936)),
FilesHash: ToPointer("a763d3c88968ebc17691900d3c14306762296df8e47a1c2d7661cee0e0c5aa6d4c082a7c128d6e719fe333b73b46fe3ae32694716ccd2efa21f5d9f049ceec6d"),
Name: ToPointer("test-package"),
Size: ToPointer(int64(1540845)),
},
}

Expand Down Expand Up @@ -71,7 +72,7 @@ func TestClient_Package(t *testing.T) {
t.Errorf("bad package description: %q != %q", *wp.Metadata.Description, *testData.Metadata.Description)
}
if *wp.Metadata.Size != *testData.Metadata.Size {
t.Errorf("bad package size: %q != %q", *wp.Metadata.Size, *testData.Metadata.Size)
t.Errorf("bad package size: %d != %d", *wp.Metadata.Size, *testData.Metadata.Size)
}
if *wp.Metadata.HashSum != *testData.Metadata.HashSum {
t.Errorf("bad package hashsum: %q != %q", *wp.Metadata.HashSum, *testData.Metadata.HashSum)
Expand All @@ -82,6 +83,9 @@ func TestClient_Package(t *testing.T) {
if *wp.Metadata.Language != *testData.Metadata.Language {
t.Errorf("bad package language: %q != %q", *wp.Metadata.Language, *testData.Metadata.Language)
}
if ToValue(wp.Metadata.ClonedFrom) != ToValue(testData.Metadata.ClonedFrom) {
t.Errorf("bad package cloned_from: %q != %q", ToValue(wp.Metadata.ClonedFrom), ToValue(testData.Metadata.ClonedFrom))
}

// Update with valid package bytes

Expand Down Expand Up @@ -128,14 +132,17 @@ func TestClient_Package(t *testing.T) {
t.Errorf("bad package description: %q != %q", *wp.Metadata.Description, *testData.Metadata.Description)
}
if *wp.Metadata.Size != *testData.Metadata.Size {
t.Errorf("bad package size: %q != %q", *wp.Metadata.Size, *testData.Metadata.Size)
t.Errorf("bad package size: %d != %d", *wp.Metadata.Size, *testData.Metadata.Size)
}
if *wp.Metadata.HashSum != *testData.Metadata.HashSum {
t.Errorf("bad package hashsum: %q != %q", *wp.Metadata.HashSum, *testData.Metadata.HashSum)
}
if *wp.Metadata.Language != *testData.Metadata.Language {
t.Errorf("bad package language: %q != %q", *wp.Metadata.Language, *testData.Metadata.Language)
}
if ToValue(wp.Metadata.ClonedFrom) != ToValue(testData.Metadata.ClonedFrom) {
t.Errorf("bad package cloned_from: %q != %q", ToValue(wp.Metadata.ClonedFrom), ToValue(testData.Metadata.ClonedFrom))
}

// Update with invalid package file path

Expand Down
18 changes: 11 additions & 7 deletions fastly/fixtures/package/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ interactions:
form: {}
headers:
User-Agent:
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0/version/2/package
- FastlyGo/9.4.0 (+github.com/fastly/go-fastly; go1.22.3)
url: https://api.fastly.com/service/OOaJq4HVv57fNDv86Qfzf5/version/2/package
method: GET
response:
body: '{"created_at":"2023-05-11T10:57:54Z","id":"yiXgwy8Xl4n1jVMAbpM813","updated_at":"2023-05-11T10:57:54Z","service_id":"sSsCewrlNQiMzZHiqD8Xr0","deleted_at":null,"metadata":{"name":"wasm-test","description":"Default
package template used by the Fastly CLI for Rust-based Compute@Edge projects.","authors":["fastly@fastly.com"],"language":"rust","size":2015936,"hashsum":"f99485bd301e23f028474d26d398da525de17a372ae9e7026891d7f85361d2540d14b3b091929c3f170eade573595e20b3405a9e29651ede59915f2e1652f616","files_hash":"a763d3c88968ebc17691900d3c14306762296df8e47a1c2d7661cee0e0c5aa6d4c082a7c128d6e719fe333b73b46fe3ae32694716ccd2efa21f5d9f049ceec6d"},"version":2}'
body: '{"created_at":"2024-05-24T20:12:52Z","deleted_at":null,"updated_at":"2024-05-24T20:12:52Z","metadata":{"name":"test-package","description":"An
empty starter kit project template.","authors":["\u003coss@fastly.com\u003e"],"language":"rust","size":1540845,"hashsum":"ecc068efcd4071d36d6460152dcc50461b649f01f28589917540a69d33e9b1477decb5f5a9a2f6c269d83a13827502c1fe1f2efc3bdd6beadaabd23e22eb84fd","files_hash":"75ff1cf4d953ff2242bb38e4a01b04503622baf4b7dc540256f4dd5fc89df5aed7fea115adab0b71caa79f6483bb846ac0d4f4f937885fb03ee35d2dfafba6f3","cloned_from":"https://github.com/fastly/compute-starter-kit-rust-empty"},"service_id":"OOaJq4HVv57fNDv86Qfzf5","version":2,"id":"ET9AMPS47ntJazcce7f0W7"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -20,7 +20,11 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 11 May 2023 10:57:55 GMT
- Fri, 24 May 2024 20:12:52 GMT
Pragma:
- no-cache
Server:
- control-gateway
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -34,9 +38,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lhr7357-LHR
- cache-chi-klot8100138-CHI, cache-nyc-kteb1890066-NYC
X-Timer:
- S1683802675.927307,VS0,VE343
- S1716581573.753162,VS0,VE183
status: 200 OK
code: 200
duration: ""
20 changes: 12 additions & 8 deletions fastly/fixtures/package/service_create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ interactions:
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
- FastlyGo/9.4.0 (+github.com/fastly/go-fastly; go1.22.3)
url: https://api.fastly.com/service
method: POST
response:
body: '{"customer_id":"51MumwLiSJyFTWhtbByYgR","comment":"go-fastly wasm client
test","name":"test_service_wasm_package","type":"wasm","id":"sSsCewrlNQiMzZHiqD8Xr0","created_at":"2023-05-11T10:57:51Z","updated_at":"2023-05-11T10:57:51Z","publish_key":"","deleted_at":null,"versions":[{"updated_at":"2023-05-11T10:57:51Z","staging":false,"deployed":false,"service_id":"sSsCewrlNQiMzZHiqD8Xr0","created_at":"2023-05-11T10:57:51Z","testing":false,"locked":false,"active":false,"deleted_at":null,"number":1,"comment":""}],"paused":false}'
body: '{"customer_id":"37OEJi7mvah1swc2IV0nQF","comment":"go-fastly wasm client
test","name":"test_service_wasm_package","type":"wasm","versions":[{"testing":false,"locked":false,"staging":false,"comment":"","deployed":false,"active":false,"number":1,"service_id":"OOaJq4HVv57fNDv86Qfzf5","deleted_at":null,"updated_at":"2024-05-24T20:12:47Z","created_at":"2024-05-24T20:12:47Z"}],"publish_key":"","paused":false,"deleted_at":null,"id":"OOaJq4HVv57fNDv86Qfzf5","updated_at":"2024-05-24T20:12:47Z","created_at":"2024-05-24T20:12:47Z"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -28,11 +28,15 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 11 May 2023 10:57:51 GMT
- Fri, 24 May 2024 20:12:48 GMT
Fastly-Ratelimit-Remaining:
- "9994"
- "994"
Fastly-Ratelimit-Reset:
- "1683802800"
- "1716584400"
Pragma:
- no-cache
Server:
- control-gateway
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -46,9 +50,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-1-CONTROL-AWS-UE2, cache-lhr7357-LHR
- cache-chi-klot8100101-CHI, cache-nyc-kteb1890066-NYC
X-Timer:
- S1683802672.502030,VS0,VE443
- S1716581567.228107,VS0,VE894
status: 200 OK
code: 200
duration: ""
18 changes: 11 additions & 7 deletions fastly/fixtures/package/service_delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ interactions:
form: {}
headers:
User-Agent:
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0
- FastlyGo/9.4.0 (+github.com/fastly/go-fastly; go1.22.3)
url: https://api.fastly.com/service/OOaJq4HVv57fNDv86Qfzf5
method: DELETE
response:
body: '{"status":"ok"}'
Expand All @@ -19,11 +19,15 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 11 May 2023 10:57:56 GMT
- Fri, 24 May 2024 20:12:56 GMT
Fastly-Ratelimit-Remaining:
- "9990"
- "990"
Fastly-Ratelimit-Reset:
- "1683802800"
- "1716584400"
Pragma:
- no-cache
Server:
- control-gateway
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -37,9 +41,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lhr7357-LHR
- cache-chi-kigq8000116-CHI, cache-nyc-kteb1890066-NYC
X-Timer:
- S1683802676.342249,VS0,VE205
- S1716581577.664175,VS0,VE222
status: 200 OK
code: 200
duration: ""
20 changes: 12 additions & 8 deletions fastly/fixtures/package/service_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ interactions:
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0/version
- FastlyGo/9.4.0 (+github.com/fastly/go-fastly; go1.22.3)
url: https://api.fastly.com/service/OOaJq4HVv57fNDv86Qfzf5/version
method: POST
response:
body: '{"service_id":"sSsCewrlNQiMzZHiqD8Xr0","number":2}'
body: '{"service_id":"OOaJq4HVv57fNDv86Qfzf5","number":2}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -21,11 +21,15 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 11 May 2023 10:57:52 GMT
- Fri, 24 May 2024 20:12:48 GMT
Fastly-Ratelimit-Remaining:
- "9993"
- "993"
Fastly-Ratelimit-Reset:
- "1683802800"
- "1716584400"
Pragma:
- no-cache
Server:
- control-gateway
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -39,9 +43,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-1-CONTROL-AWS-UE2, cache-lhr7357-LHR
- cache-chi-kigq8000141-CHI, cache-nyc-kteb1890066-NYC
X-Timer:
- S1683802672.971934,VS0,VE256
- S1716581568.128092,VS0,VE298
status: 200 OK
code: 200
duration: ""
27 changes: 17 additions & 10 deletions fastly/fixtures/package/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ interactions:
Accept:
- application/json
Content-Type:
- multipart/form-data; boundary=8477e59d28ad8ddd91a7f8f2fb9341b91e99e684d3487c7de370975ca96b
- multipart/form-data; boundary=634d65644d96bdca4e92d859b50afcecadad48119eeb6b36d5e50684dd0a
User-Agent:
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0/version/2/package
- FastlyGo/9.4.0 (+github.com/fastly/go-fastly; go1.22.3)
url: https://api.fastly.com/service/OOaJq4HVv57fNDv86Qfzf5/version/2/package
method: PUT
response:
body: '{"service_id":"sSsCewrlNQiMzZHiqD8Xr0","version":2,"deleted_at":null,"created_at":"2023-05-11T10:57:54Z","metadata":{"name":"wasm-test","description":"Default
package template used by the Fastly CLI for Rust-based Compute@Edge projects.","authors":["fastly@fastly.com"],"language":"rust","size":2015936,"hashsum":"f99485bd301e23f028474d26d398da525de17a372ae9e7026891d7f85361d2540d14b3b091929c3f170eade573595e20b3405a9e29651ede59915f2e1652f616","files_hash":"a763d3c88968ebc17691900d3c14306762296df8e47a1c2d7661cee0e0c5aa6d4c082a7c128d6e719fe333b73b46fe3ae32694716ccd2efa21f5d9f049ceec6d"},"id":"yiXgwy8Xl4n1jVMAbpM813","updated_at":"2023-05-11T10:57:54Z"}'
body: '{"service_id":"OOaJq4HVv57fNDv86Qfzf5","version":2,"id":"ET9AMPS47ntJazcce7f0W7","metadata":{"name":"test-package","description":"An
empty starter kit project template.","authors":["\u003coss@fastly.com\u003e"],"language":"rust","size":1540845,"hashsum":"ecc068efcd4071d36d6460152dcc50461b649f01f28589917540a69d33e9b1477decb5f5a9a2f6c269d83a13827502c1fe1f2efc3bdd6beadaabd23e22eb84fd","files_hash":"75ff1cf4d953ff2242bb38e4a01b04503622baf4b7dc540256f4dd5fc89df5aed7fea115adab0b71caa79f6483bb846ac0d4f4f937885fb03ee35d2dfafba6f3","wasm_metadata":{"processed-by":{"rustc":"1.78.0
(9b00956e5 2024-04-29)","fastly":"v0.0.0-unknown (Rust)","fastly_data":{"machine_info":{},"package_info":{"cloned_from":"https://github.com/fastly/compute-starter-kit-rust-empty","packages":{"anyhow":"1.0.83","lazy_static":"1.4.0","fastly-compute-project":"0.1.0","url":"2.5.0","tinyvec":"1.6.0","unicode-normalization":"0.1.23","unicode-bidi":"0.3.15","opaque-debug":"0.3.1","form_urlencoded":"1.2.1","digest":"0.9.0","http":"0.2.12","thiserror-impl":"1.0.60","fastly-macros":"0.9.12","block-buffer":"0.9.0","bytes":"1.6.0","serde_json":"1.0.117","serde":"1.0.201","ryu":"1.0.18","tinyvec_macros":"0.1.1","fastly-shared":"0.9.12","cfg-if":"1.0.0","bitflags":"1.3.2","fnv":"1.0.7","percent-encoding":"2.3.1","serde_urlencoded":"0.7.1","libc":"0.2.154","fastly-sys":"0.9.12","fastly":"0.9.12","typenum":"1.17.0","quote":"1.0.36","serde_derive":"1.0.201","time-core":"0.1.1","cpufeatures":"0.2.12","generic-array":"0.14.7","time":"0.3.23","sha2":"0.9.9","time-macros":"0.2.10","thiserror":"1.0.60","proc-macro2":"1.0.82","mime":"0.3.17","syn":"2.0.63","idna":"0.5.0","itoa":"1.0.11","unicode-ident":"1.0.12","version_check":"0.9.4"}},"script_info":{"build_script":"cargo
build --bin fastly-compute-project --release --target wasm32-wasi --color always"},"build_info":{"mem_heap_alloc":"2-5MB"}},"clang":"16.0.4
(https://github.com/llvm/llvm-project ae42196bc493ffe877a7e3dff8be32035dea4d07)"},"language":{"Rust":""}}},"updated_at":"2024-05-24T20:12:52Z","deleted_at":null,"created_at":"2024-05-24T20:12:52Z"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -24,11 +27,15 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 11 May 2023 10:57:54 GMT
- Fri, 24 May 2024 20:12:52 GMT
Fastly-Ratelimit-Remaining:
- "9992"
- "992"
Fastly-Ratelimit-Reset:
- "1683802800"
- "1716584400"
Pragma:
- no-cache
Server:
- control-gateway
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -42,9 +49,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lhr7357-LHR
- cache-chi-klot8100138-CHI, cache-nyc-kteb1890066-NYC
X-Timer:
- S1683802672.285738,VS0,VE2606
- S1716581568.453055,VS0,VE4290
status: 200 OK
code: 200
duration: ""
20 changes: 12 additions & 8 deletions fastly/fixtures/package/update_invalid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ interactions:
Accept:
- application/json
Content-Type:
- multipart/form-data; boundary=759393c3176d38e7ff81407b8d0b4dc0dfa111165d9febbdeffd3fbd5841
- multipart/form-data; boundary=74bddf4e577a8d1af55ac6e995c5eaf91606bb3ba306b9e9db754306f660
User-Agent:
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0/version/2/package
- FastlyGo/9.4.0 (+github.com/fastly/go-fastly; go1.22.3)
url: https://api.fastly.com/service/OOaJq4HVv57fNDv86Qfzf5/version/2/package
method: PUT
response:
body: '{"msg":"Bad request","detail":"Failed to extract metadata from package"}'
Expand All @@ -23,11 +23,15 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 11 May 2023 10:57:56 GMT
- Fri, 24 May 2024 20:12:56 GMT
Fastly-Ratelimit-Remaining:
- "9991"
- "991"
Fastly-Ratelimit-Reset:
- "1683802800"
- "1716584400"
Pragma:
- no-cache
Server:
- control-gateway
Status:
- 400 Bad Request
Strict-Transport-Security:
Expand All @@ -41,9 +45,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-1-CONTROL-AWS-UE2, cache-lhr7357-LHR
- cache-chi-klot8100138-CHI, cache-nyc-kteb1890066-NYC
X-Timer:
- S1683802675.312595,VS0,VE1002
- S1716581573.952296,VS0,VE3703
status: 400 Bad Request
code: 400
duration: ""
Binary file modified fastly/test_assets/package/valid.tar.gz
Binary file not shown.

0 comments on commit 9804362

Please sign in to comment.