|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | + |
| 21 | +package v1 |
| 22 | + |
| 23 | +import ( |
| 24 | + "testing" |
| 25 | + |
| 26 | + "github.com/pkg/errors" |
| 27 | + "github.com/stretchr/testify/require" |
| 28 | +) |
| 29 | + |
| 30 | +func Test_ACS_KubeConfigSpec(t *testing.T) { |
| 31 | + test := func(t *testing.T, spec *ArangoClusterSynchronizationKubeConfigSpec, error error) { |
| 32 | + err := spec.Validate() |
| 33 | + |
| 34 | + if error != nil { |
| 35 | + require.EqualError(t, err, error.Error()) |
| 36 | + } else { |
| 37 | + require.NoError(t, err) |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + type testCase struct { |
| 42 | + spec *ArangoClusterSynchronizationKubeConfigSpec |
| 43 | + error string |
| 44 | + } |
| 45 | + |
| 46 | + testCases := map[string]testCase{ |
| 47 | + "Nil": { |
| 48 | + error: "KubeConfig Spec cannot be nil", |
| 49 | + }, |
| 50 | + "Empty": { |
| 51 | + spec: &ArangoClusterSynchronizationKubeConfigSpec{}, |
| 52 | + error: "Received 3 errors: secretName: Name '' is not a valid resource name, secretKey: Name '' is not a valid resource name, namespace: Name '' is not a valid resource name", |
| 53 | + }, |
| 54 | + "Missing key & NS": { |
| 55 | + spec: &ArangoClusterSynchronizationKubeConfigSpec{ |
| 56 | + SecretName: "secret", |
| 57 | + }, |
| 58 | + error: "Received 2 errors: secretKey: Name '' is not a valid resource name, namespace: Name '' is not a valid resource name", |
| 59 | + }, |
| 60 | + "Missing NS": { |
| 61 | + spec: &ArangoClusterSynchronizationKubeConfigSpec{ |
| 62 | + SecretName: "secret", |
| 63 | + SecretKey: "key", |
| 64 | + }, |
| 65 | + error: "Received 1 errors: namespace: Name '' is not a valid resource name", |
| 66 | + }, |
| 67 | + "Valid": { |
| 68 | + spec: &ArangoClusterSynchronizationKubeConfigSpec{ |
| 69 | + SecretName: "secret", |
| 70 | + SecretKey: "key", |
| 71 | + Namespace: "ns", |
| 72 | + }, |
| 73 | + }, |
| 74 | + "Invalid": { |
| 75 | + spec: &ArangoClusterSynchronizationKubeConfigSpec{ |
| 76 | + SecretName: "secret_n", |
| 77 | + SecretKey: "key", |
| 78 | + Namespace: "ns", |
| 79 | + }, |
| 80 | + error: "Received 1 errors: secretName: Name 'secret_n' is not a valid resource name", |
| 81 | + }, |
| 82 | + } |
| 83 | + |
| 84 | + for n, tc := range testCases { |
| 85 | + t.Run(n, func(t *testing.T) { |
| 86 | + var err error |
| 87 | + if tc.error != "" { |
| 88 | + err = errors.Errorf(tc.error) |
| 89 | + } |
| 90 | + test(t, tc.spec, err) |
| 91 | + }) |
| 92 | + } |
| 93 | +} |
0 commit comments