Skip to content

Commit

Permalink
Aerospike: Add test for ClusterName
Browse files Browse the repository at this point in the history
  • Loading branch information
herrBez committed Feb 23, 2024
1 parent 972a183 commit 12d0878
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions metricbeat/module/aerospike/aerospike_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,20 @@ func getBoolPointer(value bool) *bool {
}

func TestParseClientPolicy(t *testing.T) {
sampleUser := "Test"
samplePassword := "MySecretPassword"
sampleClusterName := "TestCluster"

UserPasswordClientPolicy := as.NewClientPolicy()
UserPasswordClientPolicy.User = "Test"
UserPasswordClientPolicy.Password = "MySecretPassword"
UserPasswordClientPolicy.User = sampleUser
UserPasswordClientPolicy.Password = samplePassword

TLSPolicy := as.NewClientPolicy()
TLSPolicy.TlsConfig = &tls.Config{}

ClusterNamePolicy := as.NewClientPolicy()
ClusterNamePolicy.ClusterName = sampleClusterName

tests := []struct {
Name string
Config Config
Expand All @@ -140,15 +147,15 @@ func TestParseClientPolicy(t *testing.T) {
{
Name: "Username is set but Password is not",
Config: Config{
User: getStringPointer("Test"),
User: getStringPointer(sampleUser),
},
expectedClientPolicy: UserPasswordClientPolicy,
expectedErr: fmt.Errorf("if username is set, password should be set too"),
},
{
Name: "Password is set but Username is not",
Config: Config{
Password: getStringPointer("MySecretPassword"),
Password: getStringPointer(samplePassword),
},
expectedClientPolicy: UserPasswordClientPolicy,
expectedErr: fmt.Errorf("if password is set, username should be set too"),
Expand All @@ -165,13 +172,11 @@ func TestParseClientPolicy(t *testing.T) {
expectedErr: nil,
},
{
Name: "TLS Declaration",
Name: "Cluster Name Setting",
Config: Config{
TLS: &tlscommon.Config{
Enabled: getBoolPointer(true),
},
ClusterName: getStringPointer(sampleClusterName),
},
expectedClientPolicy: TLSPolicy,
expectedClientPolicy: ClusterNamePolicy,
expectedErr: nil,
},
}
Expand Down

0 comments on commit 12d0878

Please sign in to comment.