mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-11-24 14:10:27 +01:00
292d47eb19
* Bump github.com/docker/cli Bumps [github.com/docker/cli](https://github.com/docker/cli) from 24.0.9+incompatible to 26.1.0+incompatible. - [Commits](https://github.com/docker/cli/compare/v24.0.9...v26.1.0) --- updated-dependencies: - dependency-name: github.com/docker/cli dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Upgrade docker/docker to matching version * Tidy go.mod --------- 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>
86 lines
1.4 KiB
Go
86 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
"github.com/docker/docker/api/types/system"
|
|
)
|
|
|
|
type mockInfoClient struct {
|
|
result system.Info
|
|
err error
|
|
}
|
|
|
|
func (m *mockInfoClient) Info(context.Context) (system.Info, error) {
|
|
return m.result, m.err
|
|
}
|
|
|
|
func TestIsSwarm(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
client *mockInfoClient
|
|
expected bool
|
|
expectError bool
|
|
}{
|
|
{
|
|
"swarm",
|
|
&mockInfoClient{
|
|
result: system.Info{
|
|
Swarm: swarm.Info{
|
|
LocalNodeState: swarm.LocalNodeStateActive,
|
|
},
|
|
},
|
|
},
|
|
true,
|
|
false,
|
|
},
|
|
{
|
|
"compose",
|
|
&mockInfoClient{
|
|
result: system.Info{
|
|
Swarm: swarm.Info{
|
|
LocalNodeState: swarm.LocalNodeStateInactive,
|
|
},
|
|
},
|
|
},
|
|
false,
|
|
false,
|
|
},
|
|
{
|
|
"balena",
|
|
&mockInfoClient{
|
|
result: 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)
|
|
}
|
|
})
|
|
}
|
|
}
|