2016-10-11 01:04:39 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2022-08-24 21:03:29 +00:00
|
|
|
"time"
|
2018-06-07 19:34:18 +00:00
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2022-08-24 21:03:29 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/pointer"
|
|
|
|
"github.com/shoenig/test/must"
|
2016-10-11 01:04:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVaultConfig_Merge(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2016-10-11 01:04:39 +00:00
|
|
|
c1 := &VaultConfig{
|
2022-08-24 21:03:29 +00:00
|
|
|
Enabled: pointer.Of(false),
|
2016-10-11 01:04:39 +00:00
|
|
|
Token: "1",
|
2017-02-02 00:37:08 +00:00
|
|
|
Role: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
AllowUnauthenticated: pointer.Of(true),
|
2016-10-11 01:04:39 +00:00
|
|
|
TaskTokenTTL: "1",
|
|
|
|
Addr: "1",
|
|
|
|
TLSCaFile: "1",
|
|
|
|
TLSCaPath: "1",
|
|
|
|
TLSCertFile: "1",
|
|
|
|
TLSKeyFile: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
TLSSkipVerify: pointer.Of(true),
|
2016-10-11 01:04:39 +00:00
|
|
|
TLSServerName: "1",
|
|
|
|
}
|
|
|
|
|
|
|
|
c2 := &VaultConfig{
|
2022-08-24 21:03:29 +00:00
|
|
|
Enabled: pointer.Of(true),
|
2016-10-11 01:04:39 +00:00
|
|
|
Token: "2",
|
2017-02-02 00:37:08 +00:00
|
|
|
Role: "2",
|
2022-08-24 21:03:29 +00:00
|
|
|
AllowUnauthenticated: pointer.Of(false),
|
2016-10-11 01:04:39 +00:00
|
|
|
TaskTokenTTL: "2",
|
|
|
|
Addr: "2",
|
|
|
|
TLSCaFile: "2",
|
|
|
|
TLSCaPath: "2",
|
|
|
|
TLSCertFile: "2",
|
|
|
|
TLSKeyFile: "2",
|
|
|
|
TLSSkipVerify: nil,
|
|
|
|
TLSServerName: "2",
|
|
|
|
}
|
|
|
|
|
|
|
|
e := &VaultConfig{
|
2022-08-24 21:03:29 +00:00
|
|
|
Enabled: pointer.Of(true),
|
2016-10-11 01:04:39 +00:00
|
|
|
Token: "2",
|
2017-02-02 00:37:08 +00:00
|
|
|
Role: "2",
|
2022-08-24 21:03:29 +00:00
|
|
|
AllowUnauthenticated: pointer.Of(false),
|
2016-10-11 01:04:39 +00:00
|
|
|
TaskTokenTTL: "2",
|
|
|
|
Addr: "2",
|
|
|
|
TLSCaFile: "2",
|
|
|
|
TLSCaPath: "2",
|
|
|
|
TLSCertFile: "2",
|
|
|
|
TLSKeyFile: "2",
|
2022-08-24 21:03:29 +00:00
|
|
|
TLSSkipVerify: pointer.Of(true),
|
2016-10-11 01:04:39 +00:00
|
|
|
TLSServerName: "2",
|
|
|
|
}
|
|
|
|
|
|
|
|
result := c1.Merge(c2)
|
|
|
|
if !reflect.DeepEqual(result, e) {
|
|
|
|
t.Fatalf("bad:\n%#v\n%#v", result, e)
|
|
|
|
}
|
|
|
|
}
|
2018-06-07 19:34:18 +00:00
|
|
|
|
2022-08-24 21:03:29 +00:00
|
|
|
func TestVaultConfig_Equals(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2022-04-05 18:18:10 +00:00
|
|
|
|
2018-06-07 19:34:18 +00:00
|
|
|
c1 := &VaultConfig{
|
2022-08-24 21:03:29 +00:00
|
|
|
Enabled: pointer.Of(false),
|
2018-06-07 19:34:18 +00:00
|
|
|
Token: "1",
|
|
|
|
Role: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
Namespace: "1",
|
|
|
|
AllowUnauthenticated: pointer.Of(true),
|
2018-06-07 19:34:18 +00:00
|
|
|
TaskTokenTTL: "1",
|
|
|
|
Addr: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
ConnectionRetryIntv: time.Second,
|
2018-06-07 19:34:18 +00:00
|
|
|
TLSCaFile: "1",
|
|
|
|
TLSCaPath: "1",
|
|
|
|
TLSCertFile: "1",
|
|
|
|
TLSKeyFile: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
TLSSkipVerify: pointer.Of(true),
|
2018-06-07 19:34:18 +00:00
|
|
|
TLSServerName: "1",
|
|
|
|
}
|
|
|
|
|
|
|
|
c2 := &VaultConfig{
|
2022-08-24 21:03:29 +00:00
|
|
|
Enabled: pointer.Of(false),
|
2018-06-07 19:34:18 +00:00
|
|
|
Token: "1",
|
|
|
|
Role: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
Namespace: "1",
|
|
|
|
AllowUnauthenticated: pointer.Of(true),
|
2018-06-07 19:34:18 +00:00
|
|
|
TaskTokenTTL: "1",
|
|
|
|
Addr: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
ConnectionRetryIntv: time.Second,
|
2018-06-07 19:34:18 +00:00
|
|
|
TLSCaFile: "1",
|
|
|
|
TLSCaPath: "1",
|
|
|
|
TLSCertFile: "1",
|
|
|
|
TLSKeyFile: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
TLSSkipVerify: pointer.Of(true),
|
2018-06-07 19:34:18 +00:00
|
|
|
TLSServerName: "1",
|
|
|
|
}
|
|
|
|
|
2022-09-26 13:28:03 +00:00
|
|
|
must.Equal(t, c1, c2)
|
2018-06-07 19:34:18 +00:00
|
|
|
|
|
|
|
c3 := &VaultConfig{
|
2022-08-24 21:03:29 +00:00
|
|
|
Enabled: pointer.Of(true),
|
2018-06-07 19:34:18 +00:00
|
|
|
Token: "1",
|
|
|
|
Role: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
Namespace: "1",
|
|
|
|
AllowUnauthenticated: pointer.Of(true),
|
2018-06-07 19:34:18 +00:00
|
|
|
TaskTokenTTL: "1",
|
|
|
|
Addr: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
ConnectionRetryIntv: time.Second,
|
2018-06-07 19:34:18 +00:00
|
|
|
TLSCaFile: "1",
|
|
|
|
TLSCaPath: "1",
|
|
|
|
TLSCertFile: "1",
|
|
|
|
TLSKeyFile: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
TLSSkipVerify: pointer.Of(true),
|
2018-06-07 19:34:18 +00:00
|
|
|
TLSServerName: "1",
|
|
|
|
}
|
|
|
|
|
|
|
|
c4 := &VaultConfig{
|
2022-08-24 21:03:29 +00:00
|
|
|
Enabled: pointer.Of(false),
|
2018-06-07 19:34:18 +00:00
|
|
|
Token: "1",
|
|
|
|
Role: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
Namespace: "1",
|
|
|
|
AllowUnauthenticated: pointer.Of(true),
|
2018-06-07 19:34:18 +00:00
|
|
|
TaskTokenTTL: "1",
|
|
|
|
Addr: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
ConnectionRetryIntv: time.Second,
|
2018-06-07 19:34:18 +00:00
|
|
|
TLSCaFile: "1",
|
|
|
|
TLSCaPath: "1",
|
|
|
|
TLSCertFile: "1",
|
|
|
|
TLSKeyFile: "1",
|
2022-08-24 21:03:29 +00:00
|
|
|
TLSSkipVerify: pointer.Of(true),
|
2018-06-07 19:34:18 +00:00
|
|
|
TLSServerName: "1",
|
|
|
|
}
|
2022-08-24 21:03:29 +00:00
|
|
|
|
2022-09-26 13:28:03 +00:00
|
|
|
must.NotEqual(t, c3, c4)
|
2018-06-07 19:34:18 +00:00
|
|
|
}
|