2 * ============LICENSE_START=======================================================
3 * oom-certservice-k8s-external-provider
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package cmpv2controller
24 "github.com/go-logr/logr"
25 "github.com/stretchr/testify/assert"
26 "github.com/stretchr/testify/mock"
27 "onap.org/oom-certservice/k8s-external-provider/src/cmpv2api"
31 func Test_shouldBeInvalidCMPv2IssuerSpec_whenSpecIsEmpty(t *testing.T) {
32 spec := cmpv2api.CMPv2IssuerSpec{}
33 err := validateCMPv2IssuerSpec(spec, nil)
37 func Test_shouldBeInvalidCMPv2IssuerSpec_whenNotAllFieldsAreSet(t *testing.T) {
38 spec := cmpv2api.CMPv2IssuerSpec{}
39 spec.URL = "https://localhost"
40 spec.KeyRef = cmpv2api.SecretKeySelector{}
41 spec.KeyRef.Name = "secret-key"
43 err := validateCMPv2IssuerSpec(spec, &MockLogger{})
47 func Test_shouldBeValidCMPv2IssuerSpec_whenAllFieldsAreSet(t *testing.T) {
48 spec := cmpv2api.CMPv2IssuerSpec{}
49 spec.URL = "https://localhost"
50 spec.KeyRef = cmpv2api.SecretKeySelector{}
51 spec.KeyRef.Name = "secret-key"
52 spec.KeyRef.Key = "the-key"
54 err := validateCMPv2IssuerSpec(spec, &MockLogger{})
58 type MockLogger struct {
61 func (m *MockLogger) Info(msg string, keysAndValues ...interface{}) {}
62 func (m *MockLogger) Error(err error, msg string, keysAndValues ...interface{}) {}
63 func (m *MockLogger) Enabled() bool { return false }
64 func (m *MockLogger) V(level int) logr.Logger { return m }
65 func (m *MockLogger) WithValues(keysAndValues ...interface{}) logr.Logger { return m }
66 func (m *MockLogger) WithName(name string) logr.Logger { return m }