Skip to content

Commit b268404

Browse files
committed
Establish test standards for k8s + github dependencies
- Add test workflow - Add environment service tests
1 parent 3fcf093 commit b268404

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+8269
-54
lines changed

.github/workflows/ci_test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
concurrency:
8+
group: environment-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
test:
13+
name: Execute tests
14+
runs-on: ubuntu-24.04
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup Go with cache
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version-file: ./go.mod
22+
23+
- name: Run tests
24+
run: |
25+
go test -v ./...

.mockery.yml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ packages:
150150
filename: webhook_repository_mock.go
151151
mockname: WebhookRepositoryMock
152152
outpkg: mocks_repository_webhook
153+
github.com/unbindapp/unbind-api/internal/infrastructure/k8s:
154+
config:
155+
dir: ./mocks/infrastructure/k8s
156+
interfaces:
157+
KubeClientInterface:
158+
config:
159+
filename: kubeclient_mock.go
160+
mockname: KubeClientMock
161+
outpkg: mocks_infrastructure_k8s
153162
github.com/unbindapp/unbind-api/internal/repositories/repositories:
154163
config:
155164
dir: ./mocks/repositories
@@ -158,4 +167,40 @@ packages:
158167
config:
159168
filename: repositories_mock.go
160169
mockname: RepositoriesMock
161-
outpkg: mocks_repositories
170+
outpkg: mocks_repositories
171+
github.com/unbindapp/unbind-api/internal/integrations/github:
172+
config:
173+
dir: ./mocks/integrations/github
174+
interfaces:
175+
GithubClientInterface:
176+
config:
177+
filename: github_client_mock.go
178+
mockname: GithubClientMock
179+
outpkg: mocks_integrations_github
180+
github.com/unbindapp/unbind-api/internal/services/webooks:
181+
config:
182+
dir: ./mocks/services/webhooks
183+
interfaces:
184+
WebhooksServiceInterface:
185+
config:
186+
filename: webhooks_service_mock.go
187+
mockname: WebhooksServiceMock
188+
outpkg: mocks_services_webhooks
189+
github.com/unbindapp/unbind-api/internal/services/variables:
190+
config:
191+
dir: ./mocks/services/variables
192+
interfaces:
193+
VariablesServiceInterface:
194+
config:
195+
filename: variables_service_mock.go
196+
mockname: VariablesServiceMock
197+
outpkg: mocks_services_variables
198+
github.com/unbindapp/unbind-api/internal/deployctl:
199+
config:
200+
dir: ./mocks/deployctl
201+
interfaces:
202+
DeploymentControllerInterface:
203+
config:
204+
filename: deployctl_mock.go
205+
mockname: DeploymentControllerMock
206+
outpkg: mocks_deployctl

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ migrate\:checksum:
2323
interfaces:
2424
@echo "Generating interfaces..."
2525
@go generate ./internal/repositories/...
26+
@go generate ./internal/infrastructure/...
27+
@go generate ./internal/services/...
28+
@go generate ./internal/deployctl/...
2629
@echo "Generating mocks..."
2730
@go run github.com/vektra/mockery/v2@latest
2831

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
![GitHub License](https://img.shields.io/github/license/unbindapp/unbind-api?style=for-the-badge&color=blue)
66
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/unbindapp/unbind-api?style=for-the-badge&color=00ADD8)
7-
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/unbindapp/unbind-api/ci_master.yml?style=for-the-badge&label=BUILD)
7+
![GitHub Workflow Test Status](https://img.shields.io/github/actions/workflow/status/unbindapp/unbind-api/ci_test.yml?style=for-the-badge&label=TESTS)
88
![GitHub Stars](https://img.shields.io/github/stars/unbindapp/unbind-api?style=for-the-badge&color=gold)
99
![GitHub Issues](https://img.shields.io/github/issues/unbindapp/unbind-api?style=for-the-badge&color=red)
1010
![GitHub Pull Requests](https://img.shields.io/github/issues-pr/unbindapp/unbind-api?style=for-the-badge&color=purple)

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ require (
5959
github.com/Microsoft/go-winio v0.6.2 // indirect
6060
github.com/ProtonMail/go-crypto v1.3.0 // indirect
6161
github.com/alexflint/go-filemutex v1.3.0 // indirect
62+
github.com/alicebob/miniredis/v2 v2.35.0 // indirect
6263
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 // indirect
6364
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
6465
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
@@ -190,6 +191,7 @@ require (
190191
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
191192
github.com/xlab/treeprint v1.2.0 // indirect
192193
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
194+
github.com/yuin/gopher-lua v1.1.1 // indirect
193195
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
194196
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
195197
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.61.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
3030
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
3131
github.com/alexflint/go-filemutex v1.3.0 h1:LgE+nTUWnQCyRKbpoceKZsPQbs84LivvgwUymZXdOcM=
3232
github.com/alexflint/go-filemutex v1.3.0/go.mod h1:U0+VA/i30mGBlLCrFPGtTe9y6wGQfNAWPBTekHQ+c8A=
33+
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
34+
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
3335
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 h1:aM1rlcoLz8y5B2r4tTLMiVTrMtpfY0O8EScKJxaSaEc=
3436
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
3537
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
@@ -666,6 +668,8 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDf
666668
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
667669
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
668670
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
671+
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
672+
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
669673
github.com/zalando/postgres-operator v1.14.0 h1:C8+n26C8v6fPB1SNW+Y8X6oQoEHufzGJXJzYPlix+zw=
670674
github.com/zalando/postgres-operator v1.14.0/go.mod h1:ZTHY3sVfHgLLRpTgyR/44JcumbACeJBjztr3o1yHBdc=
671675
github.com/zclconf/go-cty v1.16.3 h1:osr++gw2T61A8KVYHoQiFbFd1Lh3JOCXc/jFLJXKTxk=

internal/deployctl/deployctl.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,31 @@ type DeploymentJobRequest struct {
4646
}
4747

4848
// Handles triggering builds for services
49+
//
50+
//go:generate go run -mod=mod github.com/vburenin/ifacemaker -f "*.go" -i DeploymentControllerInterface -p deployctl -s DeploymentController -o deployctl_iface.go
4951
type DeploymentController struct {
5052
cfg *config.Config
51-
k8s *k8s.KubeClient
53+
k8s k8s.KubeClientInterface
5254
jobQueue *queue.Queue[DeploymentJobRequest]
5355
dependentQueue *queue.Queue[DeploymentJobRequest]
5456
ctx context.Context
5557
cancelFunc context.CancelFunc
56-
repo *repositories.Repositories
57-
githubClient *github.GithubClient
58-
webhookService *webhooks_service.WebhooksService
59-
variableService *variables_service.VariablesService
58+
repo repositories.RepositoriesInterface
59+
githubClient github.GithubClientInterface
60+
webhookService webhooks_service.WebhooksServiceInterface
61+
variableService variables_service.VariablesServiceInterface
6062
}
6163

6264
func NewDeploymentController(
6365
ctx context.Context,
6466
cancel context.CancelFunc,
6567
cfg *config.Config,
66-
k8s *k8s.KubeClient,
68+
k8s k8s.KubeClientInterface,
6769
redisClient *redis.Client,
68-
repositories *repositories.Repositories,
69-
githubClient *github.GithubClient,
70-
webeehookService *webhooks_service.WebhooksService,
71-
variableService *variables_service.VariablesService) *DeploymentController {
70+
repositories repositories.RepositoriesInterface,
71+
githubClient github.GithubClientInterface,
72+
webeehookService webhooks_service.WebhooksServiceInterface,
73+
variableService variables_service.VariablesServiceInterface) *DeploymentController {
7274
jobQueue := queue.NewQueue[DeploymentJobRequest](redisClient, BUILDER_QUEUE_KEY)
7375
dependentQueue := queue.NewQueue[DeploymentJobRequest](redisClient, DEPENDENT_SERVICES_QUEUE_KEY)
7476

internal/deployctl/deployctl_iface.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)