1
0
mirror of https://github.com/offen/docker-volume-backup.git synced 2025-11-23 21:44:40 +02:00
Files
docker-volume-backup/cmd/backup/stop_restart_test.go
dependabot[bot] 6010d61283 Bump github.com/docker/cli from 28.5.2+incompatible to 29.0.2+incompatible (#676)
* Bump github.com/docker/cli

Bumps [github.com/docker/cli](https://github.com/docker/cli) from 28.5.2+incompatible to 29.0.2+incompatible.
- [Commits](https://github.com/docker/cli/compare/v28.5.2...v29.0.2)

---
updated-dependencies:
- dependency-name: github.com/docker/cli
  dependency-version: 29.0.2+incompatible
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* github.com/docker/docker has been superseded by moby packages

* Fix usage of new filter API

* Base test env off Docker 29

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Frederik Ring <frederik.ring@gmail.com>
2025-11-20 17:16:08 +01:00

108 lines
1.8 KiB
Go

package main
import (
"context"
"errors"
"testing"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/api/types/system"
"github.com/moby/moby/client"
)
type mockInfoClient struct {
result client.SystemInfoResult
err error
}
func (m *mockInfoClient) Info(context.Context, client.InfoOptions) (client.SystemInfoResult, error) {
return m.result, m.err
}
func TestIsSwarm(t *testing.T) {
tests := []struct {
name string
client *mockInfoClient
expected bool
expectError bool
}{
{
"swarm",
&mockInfoClient{
result: client.SystemInfoResult{
Info: system.Info{
Swarm: swarm.Info{
LocalNodeState: swarm.LocalNodeStateActive,
ControlAvailable: true,
},
},
},
},
true,
false,
},
{
"worker",
&mockInfoClient{
result: client.SystemInfoResult{
Info: system.Info{
Swarm: swarm.Info{
LocalNodeState: swarm.LocalNodeStateActive,
},
},
},
},
false,
false,
},
{
"compose",
&mockInfoClient{
result: client.SystemInfoResult{
Info: system.Info{
Swarm: swarm.Info{
LocalNodeState: swarm.LocalNodeStateInactive,
},
},
},
},
false,
false,
},
{
"balena",
&mockInfoClient{
result: client.SystemInfoResult{
Info: system.Info{
Swarm: swarm.Info{
LocalNodeState: "",
},
},
},
},
false,
false,
},
{
"error",
&mockInfoClient{
err: errors.New("the dinosaurs escaped"),
},
false,
true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result, err := isSwarm(test.client)
if (err != nil) != test.expectError {
t.Errorf("Unexpected error value %v", err)
}
if test.expected != result {
t.Errorf("Expected %v, got %v", test.expected, result)
}
})
}
}