mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
fix: review snapshot and post init migration logic (#158)
This commit is contained in:
parent
07d1eedae3
commit
20e3d3a15b
5 changed files with 206 additions and 11 deletions
160
pkg/endpoints/utils_test.go
Normal file
160
pkg/endpoints/utils_test.go
Normal file
|
@ -0,0 +1,160 @@
|
|||
package endpoints
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsEdgeEndpoint(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
endpoint *portainer.Endpoint
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "EdgeAgentOnDockerEnvironment",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "EdgeAgentOnKubernetesEnvironment",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnKubernetesEnvironment,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "NonEdgeEnvironment",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.DockerEnvironment,
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := IsEdgeEndpoint(tt.endpoint)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsAssociatedEdgeEndpoint(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
endpoint *portainer.Endpoint
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "AssociatedEdgeEndpoint",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
EdgeID: "some-edge-id",
|
||||
UserTrusted: true,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "NonAssociatedEdgeEndpoint",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
EdgeID: "",
|
||||
UserTrusted: true,
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "EdgeEndpointInWaitingRoom",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
EdgeID: "some-edge-id",
|
||||
UserTrusted: false,
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "NonEdgeEnvironment",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.DockerEnvironment,
|
||||
EdgeID: "some-edge-id",
|
||||
UserTrusted: true,
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := IsAssociatedEdgeEndpoint(tt.endpoint)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasDirectConnectivity(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
endpoint *portainer.Endpoint
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "NonEdgeEnvironment",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.DockerEnvironment,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "AssociatedEdgeEndpoint",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
EdgeID: "some-edge-id",
|
||||
UserTrusted: true,
|
||||
Edge: portainer.EnvironmentEdgeSettings{AsyncMode: false},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "AssociatedAsyncEdgeEndpoint",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
EdgeID: "some-edge-id",
|
||||
UserTrusted: true,
|
||||
Edge: portainer.EnvironmentEdgeSettings{AsyncMode: true},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "EdgeEndpointInWaitingRoom",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
EdgeID: "some-edge-id",
|
||||
UserTrusted: false,
|
||||
Edge: portainer.EnvironmentEdgeSettings{AsyncMode: false},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "AsyncEdgeEndpointInWaitingRoom",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
EdgeID: "some-edge-id",
|
||||
UserTrusted: false,
|
||||
Edge: portainer.EnvironmentEdgeSettings{AsyncMode: true},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := HasDirectConnectivity(tt.endpoint)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue