MCPcopy
hub / github.com/basecamp/once / TestApplyChanges

Function TestApplyChanges

internal/command/update_test.go:13–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestApplyChanges(t *testing.T) {
14 existing := docker.ApplicationSettings{
15 Name: "myapp",
16 Image: "myimage:latest",
17 Host: "app.example.com",
18 DisableTLS: false,
19 EnvVars: map[string]string{"KEY": "value"},
20 SMTP: docker.SMTPSettings{
21 Server: "smtp.example.com",
22 Port: "587",
23 Username: "user",
24 Password: "pass",
25 From: "noreply@example.com",
26 },
27 Resources: docker.ContainerResources{
28 CPUs: 2,
29 MemoryMB: 1024,
30 },
31 AutoUpdate: true,
32 Backup: docker.BackupSettings{
33 Path: "/backups",
34 AutoBackup: true,
35 },
36 }
37
38 newCmd := func() (*cobra.Command, *settingsFlags) {
39 cmd := &cobra.Command{}
40 f := &settingsFlags{}
41 f.register(cmd)
42 return cmd, f
43 }
44
45 t.Run("no flags changed returns existing", func(t *testing.T) {
46 cmd, f := newCmd()
47 result, err := f.applyChanges(cmd, existing, existing.Image)
48 require.NoError(t, err)
49 assert.True(t, existing.Equal(result))
50 })
51
52 t.Run("single flag changed", func(t *testing.T) {
53 cmd, f := newCmd()
54 require.NoError(t, cmd.Flags().Set("memory", "2048"))
55
56 result, err := f.applyChanges(cmd, existing, existing.Image)
57 require.NoError(t, err)
58 assert.Equal(t, 2048, result.Resources.MemoryMB)
59 assert.Equal(t, existing.Resources.CPUs, result.Resources.CPUs)
60 assert.Equal(t, existing.Host, result.Host)
61 assert.Equal(t, existing.EnvVars, result.EnvVars)
62 })
63
64 t.Run("multiple flags changed", func(t *testing.T) {
65 cmd, f := newCmd()
66 require.NoError(t, cmd.Flags().Set("host", "new.example.com"))
67 require.NoError(t, cmd.Flags().Set("cpus", "4"))
68 require.NoError(t, cmd.Flags().Set("auto-backup", "false"))
69
70 result, err := f.applyChanges(cmd, existing, existing.Image)

Callers

nothing calls this directly

Calls 4

registerMethod · 0.95
applyChangesMethod · 0.95
EqualMethod · 0.95
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…