mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 14:26:23 -04:00
ci: add e2e test for constellation recover (#845)
* AB#2256 Add recover e2e test * AB#2256 move test & fix minor objections * AB#2256 fix path * AB#2256 rename hacky filename
This commit is contained in:
parent
2cee7cb454
commit
ae2db08f3a
14 changed files with 202 additions and 32 deletions
|
@ -74,39 +74,59 @@ func (c *Client) PrepareWorkspace(path string, vars Variables) error {
|
|||
}
|
||||
|
||||
// CreateCluster creates a Constellation cluster using Terraform.
|
||||
func (c *Client) CreateCluster(ctx context.Context) (string, string, error) {
|
||||
func (c *Client) CreateCluster(ctx context.Context) (CreateOutput, error) {
|
||||
if err := c.tf.Init(ctx); err != nil {
|
||||
return "", "", err
|
||||
return CreateOutput{}, err
|
||||
}
|
||||
|
||||
if err := c.tf.Apply(ctx); err != nil {
|
||||
return "", "", err
|
||||
return CreateOutput{}, err
|
||||
}
|
||||
|
||||
tfState, err := c.tf.Show(ctx)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return CreateOutput{}, err
|
||||
}
|
||||
|
||||
ipOutput, ok := tfState.Values.Outputs["ip"]
|
||||
if !ok {
|
||||
return "", "", errors.New("no IP output found")
|
||||
return CreateOutput{}, errors.New("no IP output found")
|
||||
}
|
||||
ip, ok := ipOutput.Value.(string)
|
||||
if !ok {
|
||||
return "", "", errors.New("invalid type in IP output: not a string")
|
||||
return CreateOutput{}, errors.New("invalid type in IP output: not a string")
|
||||
}
|
||||
|
||||
secretOutput, ok := tfState.Values.Outputs["initSecret"]
|
||||
if !ok {
|
||||
return "", "", errors.New("no initSecret output found")
|
||||
return CreateOutput{}, errors.New("no initSecret output found")
|
||||
}
|
||||
secret, ok := secretOutput.Value.(string)
|
||||
if !ok {
|
||||
return "", "", errors.New("invalid type in initSecret output: not a string")
|
||||
return CreateOutput{}, errors.New("invalid type in initSecret output: not a string")
|
||||
}
|
||||
|
||||
return ip, secret, nil
|
||||
uidOutput, ok := tfState.Values.Outputs["uid"]
|
||||
if !ok {
|
||||
return CreateOutput{}, errors.New("no uid output found")
|
||||
}
|
||||
uid, ok := uidOutput.Value.(string)
|
||||
if !ok {
|
||||
return CreateOutput{}, errors.New("invalid type in uid output: not a string")
|
||||
}
|
||||
|
||||
return CreateOutput{
|
||||
IP: ip,
|
||||
Secret: secret,
|
||||
UID: uid,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateOutput contains the Terraform output values of a cluster creation.
|
||||
type CreateOutput struct {
|
||||
IP string
|
||||
Secret string
|
||||
UID string
|
||||
}
|
||||
|
||||
// IAMOutput contains the output information of the Terraform IAM operations.
|
||||
|
|
|
@ -2,6 +2,10 @@ output "ip" {
|
|||
value = aws_eip.lb.public_ip
|
||||
}
|
||||
|
||||
output "uid" {
|
||||
value = local.uid
|
||||
}
|
||||
|
||||
output "initSecret" {
|
||||
value = random_password.initSecret.result
|
||||
sensitive = true
|
||||
|
|
|
@ -2,6 +2,10 @@ output "ip" {
|
|||
value = azurerm_public_ip.loadbalancer_ip.ip_address
|
||||
}
|
||||
|
||||
output "uid" {
|
||||
value = local.uid
|
||||
}
|
||||
|
||||
output "initSecret" {
|
||||
value = random_password.initSecret.result
|
||||
sensitive = true
|
||||
|
|
|
@ -2,6 +2,10 @@ output "ip" {
|
|||
value = google_compute_global_address.loadbalancer_ip.address
|
||||
}
|
||||
|
||||
output "uid" {
|
||||
value = local.uid
|
||||
}
|
||||
|
||||
output "initSecret" {
|
||||
value = random_password.initSecret.result
|
||||
sensitive = true
|
||||
|
|
|
@ -214,6 +214,9 @@ func TestCreateCluster(t *testing.T) {
|
|||
"initSecret": {
|
||||
Value: "initSecret",
|
||||
},
|
||||
"uid": {
|
||||
Value: "12345abc",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -300,6 +303,34 @@ func TestCreateCluster(t *testing.T) {
|
|||
fs: afero.NewMemMapFs(),
|
||||
wantErr: true,
|
||||
},
|
||||
"no uid": {
|
||||
pathBase: "terraform",
|
||||
provider: cloudprovider.QEMU,
|
||||
vars: qemuVars,
|
||||
tf: &stubTerraform{
|
||||
showState: &tfjson.State{
|
||||
Values: &tfjson.StateValues{
|
||||
Outputs: map[string]*tfjson.StateOutput{},
|
||||
},
|
||||
},
|
||||
},
|
||||
fs: afero.NewMemMapFs(),
|
||||
wantErr: true,
|
||||
},
|
||||
"uid has wrong type": {
|
||||
pathBase: "terraform",
|
||||
provider: cloudprovider.QEMU,
|
||||
vars: qemuVars,
|
||||
tf: &stubTerraform{
|
||||
showState: &tfjson.State{
|
||||
Values: &tfjson.StateValues{
|
||||
Outputs: map[string]*tfjson.StateOutput{"uid": {Value: 42}},
|
||||
},
|
||||
},
|
||||
},
|
||||
fs: afero.NewMemMapFs(),
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
|
@ -315,15 +346,16 @@ func TestCreateCluster(t *testing.T) {
|
|||
|
||||
path := path.Join(tc.pathBase, strings.ToLower(tc.provider.String()))
|
||||
require.NoError(c.PrepareWorkspace(path, tc.vars))
|
||||
ip, initSecret, err := c.CreateCluster(context.Background())
|
||||
tfOutput, err := c.CreateCluster(context.Background())
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
assert.NoError(err)
|
||||
assert.Equal("192.0.2.100", ip)
|
||||
assert.Equal("initSecret", initSecret)
|
||||
assert.Equal("192.0.2.100", tfOutput.IP)
|
||||
assert.Equal("initSecret", tfOutput.Secret)
|
||||
assert.Equal("12345abc", tfOutput.UID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue