mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-25 00:05:17 -04:00
monorepo
Co-authored-by: Malte Poll <mp@edgeless.systems> Co-authored-by: katexochen <katexochen@users.noreply.github.com> Co-authored-by: Daniel Weiße <dw@edgeless.systems> Co-authored-by: Thomas Tendyck <tt@edgeless.systems> Co-authored-by: Benedict Schlueter <bs@edgeless.systems> Co-authored-by: leongross <leon.gross@rub.de> Co-authored-by: Moritz Eckert <m1gh7ym0@gmail.com>
This commit is contained in:
commit
2d8fcd9bf4
362 changed files with 50980 additions and 0 deletions
120
cli/ec2/client/client_test.go
Normal file
120
cli/ec2/client/client_test.go
Normal file
|
@ -0,0 +1,120 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/cli/ec2"
|
||||
"github.com/edgelesssys/constellation/internal/state"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetState(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
client Client
|
||||
wantState state.ConstellationState
|
||||
wantErr bool
|
||||
}{
|
||||
"successful get": {
|
||||
client: Client{
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
securityGroup: "sg",
|
||||
},
|
||||
wantState: state.ConstellationState{
|
||||
CloudProvider: "AWS",
|
||||
EC2Instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
EC2SecurityGroup: "sg",
|
||||
},
|
||||
},
|
||||
"client without security group": {
|
||||
client: Client{
|
||||
instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"client without instances": {
|
||||
client: Client{
|
||||
securityGroup: "sg",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
stat, err := tc.client.GetState()
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
assert.Equal(tc.wantState, stat)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetState(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
state state.ConstellationState
|
||||
wantInstances ec2.Instances
|
||||
wantSecurityGroup string
|
||||
wantErr bool
|
||||
}{
|
||||
"successful set": {
|
||||
state: state.ConstellationState{
|
||||
CloudProvider: "AWS",
|
||||
EC2SecurityGroup: "sg-test",
|
||||
EC2Instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
},
|
||||
wantInstances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
wantSecurityGroup: "sg-test",
|
||||
},
|
||||
"state without cloudprovider": {
|
||||
state: state.ConstellationState{
|
||||
EC2SecurityGroup: "sg-test",
|
||||
EC2Instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"state with incorrect cloudprovider": {
|
||||
state: state.ConstellationState{
|
||||
CloudProvider: "incorrect",
|
||||
EC2SecurityGroup: "sg-test",
|
||||
EC2Instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"state without instances": {
|
||||
state: state.ConstellationState{
|
||||
CloudProvider: "AWS",
|
||||
EC2SecurityGroup: "sg-test",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"state without security group": {
|
||||
state: state.ConstellationState{
|
||||
CloudProvider: "AWS",
|
||||
EC2Instances: ec2.Instances{"id-1": {}, "id-2": {}, "id-3": {}},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
client := &Client{}
|
||||
|
||||
err := client.SetState(tc.state)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
assert.Equal(tc.wantInstances, client.instances)
|
||||
assert.Equal(tc.wantSecurityGroup, client.securityGroup)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue