Skip to content

Commit ff29bd3

Browse files
committed
Fix #34: Added tests for git apply
1 parent dba7980 commit ff29bd3

File tree

8 files changed

+60
-5
lines changed

8 files changed

+60
-5
lines changed

cmd/clace/app_cmds.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Examples:
201201
}
202202

203203
func printCreateResult(cCtx *cli.Context, createResult types.AppCreateResponse) {
204-
fmt.Printf(" App: %s\n", createResult.Path)
204+
fmt.Printf(" App: %s\n", &createResult.AppPathDomain)
205205
if createResult.HttpUrl != "" {
206206
fmt.Printf(" HTTP Url: %s\n", createResult.HttpUrl)
207207
}

internal/server/app_apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (s *Server) createApp(ctx context.Context, currentTx types.Transaction, app
243243
}
244244

245245
ret := &types.AppCreateResponse{
246-
Path: appEntry.String(),
246+
AppPathDomain: appEntry.AppPathDomain(),
247247
HttpUrl: s.getAppHttpUrl(appEntry),
248248
HttpsUrl: s.getAppHttpsUrl(appEntry),
249249
DryRun: dryRun,

internal/server/apply.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"context"
99
"encoding/json"
1010
"fmt"
11+
"maps"
1112
"os"
1213
"path/filepath"
1314
"reflect"
15+
"slices"
1416

1517
"github.com/BurntSushi/toml"
1618
"github.com/claceio/clace/internal/app/appfs"
@@ -336,8 +338,25 @@ func (s *Server) Apply(ctx context.Context, applyPath string, appPathGlob string
336338
}
337339
}
338340

341+
// Get list of all updated apps
342+
allUpdatedApps := []types.AppPathDomain{}
343+
allUpdatedApps = append(allUpdatedApps, updateResults...)
344+
allUpdatedApps = append(allUpdatedApps, reloadResults...)
345+
allUpdatedApps = append(allUpdatedApps, promoteResults...)
346+
for _, app := range approveResults {
347+
allUpdatedApps = append(allUpdatedApps, app.AppPathDomain)
348+
}
349+
for _, app := range createResults {
350+
allUpdatedApps = append(allUpdatedApps, app.AppPathDomain)
351+
}
352+
allAppMap := make(map[types.AppPathDomain]bool)
353+
for _, app := range allUpdatedApps {
354+
allAppMap[app] = true
355+
}
356+
allUpdatedApps = slices.Collect(maps.Keys(allAppMap))
357+
339358
// Commit the transaction if not dry run and update the in memory app store
340-
if err := s.CompleteTransaction(ctx, tx, updateResults, dryRun, "apply"); err != nil {
359+
if err := s.CompleteTransaction(ctx, tx, allUpdatedApps, dryRun, "apply"); err != nil {
341360
return nil, err
342361
}
343362

internal/server/apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (a *AppStore) DeleteAppsAudit(ctx context.Context, pathDomain []types.AppPa
220220
for _, pd := range pathDomain {
221221
appInfo, ok := appMap[pd.String()]
222222
if !ok {
223-
return fmt.Errorf("app not found: %s", pd)
223+
continue
224224
}
225225

226226
event.Target = pd.String()

internal/types/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type AppListResponse struct {
101101
}
102102

103103
type AppCreateResponse struct {
104-
Path string `json:"path"`
104+
AppPathDomain AppPathDomain `json:"app_path_domain"`
105105
DryRun bool `json:"dry_run"`
106106
HttpUrl string `json:"http_url"`
107107
HttpsUrl string `json:"https_url"`

tests/apply_files/apply_git.ace

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
app("/applytest/test1", "github.com/claceio/apps/system/disk_usage")
2+
app("/applytest/test2", "github.com/claceio/apps/system/memory_usage")
3+
app("/applytest/test3", "github.com/claceio/apps/system/list_files")

tests/apply_files/apply_git2.ace

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
app("/applytest/test1", "github.com/claceio/apps/system/disk_usage", auth="system")
2+
app("/applytest/test2", "github.com/claceio/apps/system/memory_usage", git_auth="abc")
3+
app("/applytest/test3", "github.com/claceio/apps/system/list_files", spec="python-flask")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
config:
2+
env:
3+
CL_CONFIG_FILE: clace.toml
4+
GOCOVERDIR: ${GOCOVERDIR}/../client
5+
PATH: ${PATH}
6+
tests:
7+
apply0010: ## create all apps
8+
command: ../clace apply ./apply_files/apply_git.ace all
9+
stdout: "3 app(s) created, 0 app(s) updated, 0 app(s) reloaded, 0 app(s) approved, 0 app(s) promoted."
10+
apply0020:
11+
command: ../clace apply --approve --promote --reload=all ./apply_files/apply_git.ace all
12+
stdout: "0 app(s) created, 0 app(s) updated, 6 app(s) reloaded, 3 app(s) approved, 3 app(s) promoted."
13+
apply0030: # check curl after approval
14+
command: curl -su "admin:qwerty" localhost:25222/applytest/test1/
15+
stdout: "Disk Usage"
16+
apply0040: # check curl after approval for stage
17+
command: curl -su "admin:qwerty" localhost:25222/applytest/test1_cl_stage/
18+
stdout: "Disk Usage"
19+
20+
apply0050: ## check auth error
21+
command: ../clace apply ./apply_files/apply_git2.ace /applytest/test1
22+
stderr: "app /applytest/test1 authentication changed, cannot apply changes"
23+
exit-code: 1
24+
apply0051: ## check git auth error
25+
command: ../clace apply ./apply_files/apply_git2.ace /applytest/test2
26+
stderr: "app /applytest/test2 git auth changed, cannot apply changes"
27+
exit-code: 1
28+
apply0052: ## check spec update
29+
command: ../clace apply ./apply_files/apply_git2.ace /applytest/test3
30+
stdout: "0 app(s) created, 1 app(s) updated, 1 app(s) reloaded, 0 app(s) approved, 0 app(s) promoted"

0 commit comments

Comments
 (0)