Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more test cases for different scenarios #64

Merged
merged 4 commits into from
Aug 14, 2024

Conversation

linglingye001
Copy link
Contributor

No description provided.

@linglingye001 linglingye001 marked this pull request as ready for review August 9, 2024 03:27
@linglingye001 linglingye001 changed the title Add more test for refresh scenarios Add more test cases for different scenarios Aug 9, 2024

// when reconcile is triggered by single component refresh
// only update the corresponding component reconcile state and next refresh time
It("Should update reconcile state when keyValue pageEtag, featureFlag pageEtag and secret references updated when configuration, secret and feature flag refresh enabled", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update the corresponding target's reconcile state, and those that shouldn't be updated should be as is.

}]).Should(Equal(updatedFeatureFlagEtags[acpv1.Selector{
KeyFilter: &wildcard,
}]))
Expect(processor.ReconciliationState.NextSecretReferenceRefreshReconcileTime).Should(Equal(expectedNextSecretReferenceRefreshReconcileTime))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert the NextKeyValueRefreshReconcileTime and NextFeatureFlagRefreshReconcileTime not been updated, still keep the previous expectedNextKeyValueRefreshReconcileTime and cachedNextFeatureFlagRefreshReconcileTime value.

Comment on lines 152 to 456
secretResult["testSecretKey"] = []byte("testSecretValue")
existingSecrets := make(map[string]corev1.Secret)
existingSecrets[secretName] = corev1.Secret{
Data: secretResult,
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: fakeSecretResourceVersion,
},
}

var fakeId azsecrets.ID = "fakeSecretId"
var cachedFakeId azsecrets.ID = "cachedFakeSecretId"

secretMetadata := make(map[string]loader.KeyVaultSecretMetadata)
secretMetadata2 := make(map[string]loader.KeyVaultSecretMetadata)
cachedSecretReferences := make(map[string]*loader.TargetSecretReference)
secretMetadata["testSecretKey"] = loader.KeyVaultSecretMetadata{
SecretId: &fakeId,
}
secretMetadata2["testSecretKey"] = loader.KeyVaultSecretMetadata{
SecretId: &cachedFakeId,
}
cachedSecretReferences[secretName] = &loader.TargetSecretReference{
Type: corev1.SecretType("Opaque"),
SecretsMetadata: secretMetadata2,
SecretResourceVersion: fakeSecretResourceVersion,
}

allSettings := &loader.TargetKeyValueSettings{
SecretSettings: map[string]corev1.Secret{
secretName: {
Data: secretResult,
Type: corev1.SecretType("Opaque"),
},
},
SecretReferences: map[string]*loader.TargetSecretReference{
secretName: {
Type: corev1.SecretType("Opaque"),
SecretsMetadata: secretMetadata,
},
},
}

configProvider := &acpv1.AzureAppConfigurationProvider{
TypeMeta: metav1.TypeMeta{
APIVersion: "appconfig.kubernetes.config/v1",
Kind: "AzureAppConfigurationProvider",
},
ObjectMeta: metav1.ObjectMeta{
Name: providerName,
Namespace: ProviderNamespace,
Generation: 1,
},
Spec: acpv1.AzureAppConfigurationProviderSpec{
Endpoint: &EndpointName,
Target: acpv1.ConfigurationGenerationParameters{
ConfigMapName: configMapName,
ConfigMapData: &acpv1.ConfigMapDataOptions{
Type: "json",
Key: "filestyle.json",
},
},
Secret: &acpv1.SecretReference{
Target: acpv1.SecretGenerationParameters{
SecretName: secretName,
},
Refresh: &acpv1.RefreshSettings{
Interval: "1m",
Enabled: true,
},
},
},
}

fakeResourceVersion := "1"
tmpTime := metav1.Now()
processor := AppConfigurationProviderProcessor{
Context: ctx,
Retriever: mockConfigurationSettings,
Provider: configProvider,
ShouldReconcile: false,
Settings: &loader.TargetKeyValueSettings{},
ReconciliationState: &ReconciliationState{
NextSecretReferenceRefreshReconcileTime: tmpTime,
ExistingSecretReferences: cachedSecretReferences,
Generation: 1,
ConfigMapResourceVersion: &fakeResourceVersion,
},
CurrentTime: metav1.NewTime(tmpTime.Time.Add(1 * time.Minute)),
RefreshOptions: &RefreshOptions{},
}

mockConfigurationSettings.EXPECT().ResolveSecretReferences(gomock.Any(), gomock.Any(), gomock.Any()).Return(allSettings, nil)

_ = processor.PopulateSettings(&corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{
ResourceVersion: fakeResourceVersion,
}}, existingSecrets)

_, _ = processor.Finish()

Expect(processor.ReconciliationState.ExistingSecretReferences).Should(Equal(allSettings.SecretReferences))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need these tests? Shouldn't it has been covered by the last one?

@linglingye001 linglingye001 merged commit af334bc into release/v2/stable Aug 14, 2024
3 checks passed
@linglingye001 linglingye001 deleted the user/linglingye/addTest branch August 14, 2024 05:18
linglingye001 added a commit that referenced this pull request Nov 8, 2024
* add more test for refresh scenarios

* add more test cases

* add more refresh test cases

* resolve comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants