forked from kubernetes-sigs/cluster-api-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add json tags and tests for providerconfig and provider status
- Loading branch information
Showing
10 changed files
with
187 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 0 additions & 58 deletions
58
pkg/apis/awsproviderconfig/v1alpha1/awsmachineproviderconfig_types_test.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
apiv1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"reflect" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestEncodeAndDecodeProviderStatus(t *testing.T) { | ||
|
||
codec, err := NewCodec() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
time := metav1.Time{ | ||
Time: time.Date(2018, 6, 3, 0, 0, 0, 0, time.Local), | ||
} | ||
|
||
instanceState := "running" | ||
instanceID := "id" | ||
providerStatus := &AWSMachineProviderStatus{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "AWSMachineProviderStatus", | ||
APIVersion: "awsproviderconfig.k8s.io/v1alpha1", | ||
}, | ||
InstanceState: &instanceState, | ||
InstanceID: &instanceID, | ||
Conditions: []AWSMachineProviderCondition{ | ||
{ | ||
Type: "MachineCreation", | ||
Status: "True", | ||
Reason: "MachineCreationSucceeded", | ||
Message: "machine successfully created", | ||
LastTransitionTime: time, | ||
LastProbeTime: time, | ||
}, | ||
}, | ||
} | ||
providerStatusEncoded, err := codec.EncodeProviderStatus(providerStatus) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
providerStatusDecoded := &AWSMachineProviderStatus{} | ||
codec.DecodeProviderStatus(providerStatusEncoded, providerStatusDecoded) | ||
if !reflect.DeepEqual(providerStatus, providerStatusDecoded) { | ||
t.Errorf("failed EncodeProviderStatus/DecodeProviderStatus. Expected: %+v, got: %+v", providerStatus, providerStatusDecoded) | ||
} | ||
} | ||
|
||
func TestEncodeAndDecodeProviderConfig(t *testing.T) { | ||
codec, err := NewCodec() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
publicIP := true | ||
amiID := "id" | ||
awsCredentialsSecretName := "test" | ||
clusterID := "test" | ||
|
||
providerConfig := &AWSMachineProviderConfig{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "AWSMachineProviderConfig", | ||
APIVersion: "awsproviderconfig.k8s.io/v1alpha1", | ||
}, | ||
AMI: AWSResourceReference{ | ||
Filters: []Filter{ | ||
{ | ||
Name: "tag:image_stage", | ||
Values: []string{"base"}, | ||
}, | ||
{ | ||
Name: "tag:operating_system", | ||
Values: []string{"rhel"}, | ||
}, | ||
{ | ||
Name: "tag:ready", | ||
Values: []string{"yes"}, | ||
}, | ||
}, | ||
ID: &amiID, | ||
}, | ||
CredentialsSecret: &apiv1.LocalObjectReference{ | ||
Name: awsCredentialsSecretName, | ||
}, | ||
InstanceType: "m4.xlarge", | ||
Placement: Placement{ | ||
Region: "us-east-1", | ||
AvailabilityZone: "us-east-1a", | ||
}, | ||
Subnet: AWSResourceReference{ | ||
Filters: []Filter{ | ||
{ | ||
Name: "tag:Name", | ||
Values: []string{clusterID}, | ||
}, | ||
}, | ||
}, | ||
Tags: []TagSpecification{ | ||
{ | ||
Name: "openshift-node-group-config", | ||
Value: "node-config-master", | ||
}, | ||
{ | ||
Name: "host-type", | ||
Value: "master", | ||
}, | ||
{ | ||
Name: "sub-host-type", | ||
Value: "default", | ||
}, | ||
}, | ||
SecurityGroups: []AWSResourceReference{ | ||
{ | ||
Filters: []Filter{ | ||
{ | ||
Name: "tag:Name", | ||
Values: []string{clusterID}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
PublicIP: &publicIP, | ||
} | ||
|
||
providerConfigEncoded, err := codec.EncodeProviderConfig(providerConfig) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
providerConfigDecoded := &AWSMachineProviderConfig{} | ||
codec.DecodeProviderConfig(providerConfigEncoded, providerConfigDecoded) | ||
|
||
if !reflect.DeepEqual(providerConfig, providerConfigDecoded) { | ||
t.Errorf("failed EncodeProviderConfig/DecodeProviderConfig. Expected: %+v, got: %+v", providerConfig, providerConfigDecoded) | ||
} | ||
} |
Oops, something went wrong.