mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
add multi files config test and some more
This commit is contained in:
parent
e04c0116f5
commit
96b1817d62
@ -17,6 +17,11 @@ type validatable struct {
|
|||||||
Test bool
|
Test bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type multiple struct {
|
||||||
|
Test bool
|
||||||
|
MoreData string
|
||||||
|
}
|
||||||
|
|
||||||
func (v *validatable) Validate() error {
|
func (v *validatable) Validate() error {
|
||||||
if v.Test {
|
if v.Test {
|
||||||
return nil
|
return nil
|
||||||
@ -33,22 +38,25 @@ func TestRead(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
wantErr bool
|
wantErr bool
|
||||||
|
want interface{}
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"not supoorted config file error",
|
"not supoorted config file error",
|
||||||
args{
|
args{
|
||||||
configFiles: []string{"notsupported.unknown"},
|
configFiles: []string{"notsupported.unknown"},
|
||||||
obj: nil,
|
obj: &test{},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
|
&test{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"non existing config file error",
|
"non existing config file error",
|
||||||
args{
|
args{
|
||||||
configFiles: []string{"nonexisting.yaml"},
|
configFiles: []string{"nonexisting.yaml"},
|
||||||
obj: nil,
|
obj: &test{},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
|
&test{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"non parsable config file error",
|
"non parsable config file error",
|
||||||
@ -57,6 +65,7 @@ func TestRead(t *testing.T) {
|
|||||||
obj: &test{},
|
obj: &test{},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
|
&test{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid parsable config file error",
|
"invalid parsable config file error",
|
||||||
@ -65,6 +74,16 @@ func TestRead(t *testing.T) {
|
|||||||
obj: &validatable{},
|
obj: &validatable{},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
|
&validatable{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"multiple files, one non parsable error ",
|
||||||
|
args{
|
||||||
|
configFiles: []string{"./testdata/non_parsable.json", "./testdata/more_data.yaml"},
|
||||||
|
obj: &multiple{},
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
&multiple{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parsable config file ok",
|
"parsable config file ok",
|
||||||
@ -73,6 +92,16 @@ func TestRead(t *testing.T) {
|
|||||||
obj: &test{},
|
obj: &test{},
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
|
&test{Test: true},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"multiple parsable config files ok",
|
||||||
|
args{
|
||||||
|
configFiles: []string{"./testdata/valid.json", "./testdata/more_data.yaml"},
|
||||||
|
obj: &multiple{},
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
&multiple{Test: true, MoreData: "data"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid parsable config file ok",
|
"valid parsable config file ok",
|
||||||
@ -81,6 +110,7 @@ func TestRead(t *testing.T) {
|
|||||||
obj: &validatable{},
|
obj: &validatable{},
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
|
&validatable{Test: true},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@ -88,6 +118,9 @@ func TestRead(t *testing.T) {
|
|||||||
if err := Read(tt.args.obj, tt.args.configFiles...); (err != nil) != tt.wantErr {
|
if err := Read(tt.args.obj, tt.args.configFiles...); (err != nil) != tt.wantErr {
|
||||||
t.Errorf("Read() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("Read() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
|
if !reflect.DeepEqual(tt.args.obj, tt.want) {
|
||||||
|
t.Errorf("Read() got = %v, want = %v", tt.args.obj, tt.want)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
internal/config/testdata/more_data.yaml
vendored
Normal file
1
internal/config/testdata/more_data.yaml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
MoreData: data
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//TODO: refactor test style
|
||||||
func TestDecrypt_OK(t *testing.T) {
|
func TestDecrypt_OK(t *testing.T) {
|
||||||
encryptedpw, err := EncryptAESString("ThisIsMySecretPw", "passphrasewhichneedstobe32bytes!")
|
encryptedpw, err := EncryptAESString("ThisIsMySecretPw", "passphrasewhichneedstobe32bytes!")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
90
internal/crypto/code_mock.go
Normal file
90
internal/crypto/code_mock.go
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
|
// Source: code.go
|
||||||
|
|
||||||
|
// Package crypto is a generated GoMock package.
|
||||||
|
package crypto
|
||||||
|
|
||||||
|
import (
|
||||||
|
gomock "github.com/golang/mock/gomock"
|
||||||
|
reflect "reflect"
|
||||||
|
time "time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockGenerator is a mock of Generator interface
|
||||||
|
type MockGenerator struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockGeneratorMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockGeneratorMockRecorder is the mock recorder for MockGenerator
|
||||||
|
type MockGeneratorMockRecorder struct {
|
||||||
|
mock *MockGenerator
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockGenerator creates a new mock instance
|
||||||
|
func NewMockGenerator(ctrl *gomock.Controller) *MockGenerator {
|
||||||
|
mock := &MockGenerator{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockGeneratorMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use
|
||||||
|
func (m *MockGenerator) EXPECT() *MockGeneratorMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// Length mocks base method
|
||||||
|
func (m *MockGenerator) Length() uint {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Length")
|
||||||
|
ret0, _ := ret[0].(uint)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Length indicates an expected call of Length
|
||||||
|
func (mr *MockGeneratorMockRecorder) Length() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Length", reflect.TypeOf((*MockGenerator)(nil).Length))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expiry mocks base method
|
||||||
|
func (m *MockGenerator) Expiry() time.Duration {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Expiry")
|
||||||
|
ret0, _ := ret[0].(time.Duration)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expiry indicates an expected call of Expiry
|
||||||
|
func (mr *MockGeneratorMockRecorder) Expiry() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Expiry", reflect.TypeOf((*MockGenerator)(nil).Expiry))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alg mocks base method
|
||||||
|
func (m *MockGenerator) Alg() Crypto {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Alg")
|
||||||
|
ret0, _ := ret[0].(Crypto)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alg indicates an expected call of Alg
|
||||||
|
func (mr *MockGeneratorMockRecorder) Alg() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Alg", reflect.TypeOf((*MockGenerator)(nil).Alg))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runes mocks base method
|
||||||
|
func (m *MockGenerator) Runes() []rune {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Runes")
|
||||||
|
ret0, _ := ret[0].([]rune)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runes indicates an expected call of Runes
|
||||||
|
func (mr *MockGeneratorMockRecorder) Runes() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Runes", reflect.TypeOf((*MockGenerator)(nil).Runes))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user