Skip to content

Commit

Permalink
chore: run examples in on-pull-request workflow (#289)
Browse files Browse the repository at this point in the history
* chore: add examples step to run examples; update few examples to add cache clean up

* chore: add buil step

* fix: build examples step
  • Loading branch information
poppoerika authored Mar 17, 2023
1 parent bd87e16 commit c7de675
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@ jobs:
exit 1
fi
- name: Build
run: make build

- name: Build examples
run: make build-examples

- name: Run test
run: make test
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ test:
.PHONY: vendor
vendor:
go mod vendor

.PHONY: build-examples
build:
cd examples
go build ./...

9 changes: 9 additions & 0 deletions examples/set-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ func printSet() {
}
}

func cleanUp() {
_, err := client.DeleteCache(ctx, &momento.DeleteCacheRequest{CacheName: cacheName})
if err != nil {
panic(err)
}
}

func main() {
setup()

Expand All @@ -137,4 +144,6 @@ func main() {

removeElements(elements)
printSet()

cleanUp()
}
8 changes: 7 additions & 1 deletion examples/sortedset-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func main() {
}

displayElements(setName, descendingResp)

// Clean up the cache
_, err = client.DeleteCache(ctx, &momento.DeleteCacheRequest{CacheName: cacheName})
if err != nil {
panic(err)
}
}

func getClient() momento.CacheClient {
Expand All @@ -96,7 +102,7 @@ func getClient() momento.CacheClient {

func setupCache(client momento.CacheClient, ctx context.Context) {
_, err := client.CreateCache(ctx, &momento.CreateCacheRequest{
CacheName: "test-cache",
CacheName: cacheName,
})
if err != nil {
panic(err)
Expand Down

0 comments on commit c7de675

Please sign in to comment.