Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GiGurra committed Jul 14, 2023
1 parent a2a855b commit 8ade2dd
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 44 deletions.
12 changes: 12 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# see recommended basic mockery config:
# https://vektra.github.io/mockery/latest/configuration/#recommended-basic-config
with-expecter: True
all: True
filename: "{{.InterfaceName}}.go"
outpkg: mocks
dir: mocks
keeptree: False
packages:
github.com/gigurra/flycd/internal/fly_client: { }
github.com/gigurra/flycd/internal/flycd: { }

2 changes: 1 addition & 1 deletion cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Cmd(deployService flycd.DeployService) *cobra.Command {
fmt.Printf("Deploying from: %s\n", path)

deployCfg := model.
NewDeployConfig().
NewDefaultDeployConfig().
WithRetries(1).
WithForce(*flags.force).
WithAbortOnFirstError(*flags.abortEarly)
Expand Down
4 changes: 2 additions & 2 deletions cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func Cmd(

if !appExists {

deployCfg := model.NewDeployConfig().WithRetries(0)
deployCfg := model.NewDefaultDeployConfig().WithRetries(0)

fmt.Printf("Creating a dummy app '%s' to reserve the name\n", appName)
_, err := deployService.DeployAppFromInlineConfig(ctx, deployCfg, model.AppConfig{
Expand Down Expand Up @@ -197,7 +197,7 @@ func Cmd(
// Deploy it!
fmt.Printf("Deploying flycd in monitoring mode to fly.io\n")
deployCfg := model.
NewDeployConfig().
NewDefaultDeployConfig().
WithForce(true).
WithRetries(0)
_, err = deployService.DeployAppFromInlineConfig(ctx, deployCfg, model.AppConfig{
Expand Down
2 changes: 1 addition & 1 deletion cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func Cmd(
fmt.Printf("Syncing/Deploying all apps in %s\n", path)

deployCfg := model.
NewDeployConfig().
NewDefaultDeployConfig().
WithAbortOnFirstError(false)

_, err := deployService.DeployAll(ctx, path, deployCfg)
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.6.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRM
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
Expand Down
70 changes: 34 additions & 36 deletions internal/flycd/deployment_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,42 @@ package flycd

import (
"context"
"github.com/gigurra/flycd/internal/fly_client"
"fmt"
"github.com/gigurra/flycd/internal/flycd/model"
"github.com/gigurra/flycd/internal/flycd/util/util_work_dir"
"github.com/gigurra/flycd/mocks"
"github.com/stretchr/testify/mock"
"testing"
)

type fakeFlyClient struct {
}

func (f fakeFlyClient) CreateOrgToken(_ context.Context, _ string) (string, error) { panic("not used") }

func (f fakeFlyClient) ExistsSecret(ctx context.Context, cmd fly_client.ExistsSecretCmd) (bool, error) {
//TODO implement me
panic("implement me")
}
func TestDeployFromFolder(t *testing.T) {
ctx := context.Background()
flyClient := mocks.NewMockFlyClient(t)
deployService := NewDeployService(flyClient)
deployCfg := model.
NewDefaultDeployConfig().
WithAbortOnFirstError(true).
WithRetries(0)

fmt.Printf("flyClient: %+v\n", flyClient)

flyClient.
EXPECT().
ExistsApp(mock.Anything, mock.Anything).
Return(false, nil)

flyClient.
EXPECT().
CreateNewApp(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)

flyClient.
EXPECT().
DeployExistingApp(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)

_, err := deployService.DeployAppFromFolder(ctx, "../../test/test-projects/merge-cfg/regular/app1", deployCfg)
if err != nil {
t.Fatalf("DeployAppFromFolder failed: %v", err)
}

func (f fakeFlyClient) StoreSecret(ctx context.Context, cmd fly_client.StoreSecretCmd) error {
//TODO implement me
panic("implement me")
}

func (f fakeFlyClient) ExistsApp(ctx context.Context, name string) (bool, error) {
//TODO implement me
panic("implement me")
}

func (f fakeFlyClient) GetDeployedAppConfig(ctx context.Context, name string) (model.AppConfig, error) {
//TODO implement me
panic("implement me")
}

func (f fakeFlyClient) CreateNewApp(ctx context.Context, cfg model.AppConfig, tempDir util_work_dir.WorkDir, twoStep bool) error {
//TODO implement me
panic("implement me")
}

func (f fakeFlyClient) DeployExistingApp(ctx context.Context, cfg model.AppConfig, tempDir util_work_dir.WorkDir, deployCfg model.DeployConfig) error {
//TODO implement me
panic("implement me")
}

var _ fly_client.FlyClient = &fakeFlyClient{}
2 changes: 1 addition & 1 deletion internal/flycd/model/deploy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type DeployConfig struct {
AbortOnFirstError bool
}

func NewDeployConfig() DeployConfig {
func NewDefaultDeployConfig() DeployConfig {
return DeployConfig{
Force: false,
Retries: 2,
Expand Down
2 changes: 1 addition & 1 deletion internal/flycd/webhook_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (w WebHookServiceImpl) HandleGithubWebhook(payload github.PushWebhookPayloa
}

deployCfg := model.
NewDeployConfig().
NewDefaultDeployConfig().
WithRetries(1).
WithForce(false)
_, err := w.deployService.DeployAppFromFolder(ctx, app.Path, deployCfg)
Expand Down
3 changes: 3 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

//go:generate mockery
2 changes: 2 additions & 0 deletions scripts/bump_version.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e

# check that the build works
go clean ./...
rm -rf mocks
go generate ./...
go build ./...
go test ./...
go clean ./...
Expand Down
2 changes: 2 additions & 0 deletions scripts/publish_latest_img.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e

# check that the build works
go clean ./...
rm -rf mocks
go generate ./...
go build ./...
go test ./...
go clean ./...
Expand Down
2 changes: 2 additions & 0 deletions scripts/publish_release.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# check that the build works
go clean ./...
rm -rf mocks
go generate ./...
go build ./...
go test ./...
go clean ./...
Expand Down
3 changes: 1 addition & 2 deletions test/test-projects/merge-cfg/regular/app1/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ app: app1
primary_region: arn
org: personal
source:
type: git
repo: [email protected]:TestUser/TestRepo.git
type: local

0 comments on commit 8ade2dd

Please sign in to comment.