github.com/Venafi/vcert/v5@v5.10.2/pkg/venafi/cloud/error_test.go (about) 1 /* 2 * Copyright 2018 Venafi, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cloud 18 19 import ( 20 "testing" 21 ) 22 23 func TestParseResponseErrors(t *testing.T) { 24 data := []byte("{\"errors\":[{\"code\":10128,\"message\":\"Invalid change in apiKey status\",\"args\":[]}]}") 25 errors, err := parseResponseErrors(data) 26 if err != nil { 27 t.Fatalf("err is not nil, err: %s", err) 28 } 29 30 if len(errors) != 1 { 31 t.Fatalf("Parsed error count was not what was expected. Expected: 1 Actual: %d", len(errors)) 32 } 33 } 34 35 func TestParseResponseErrorWithArgs(t *testing.T) { 36 data := []byte("{\"errors\": [{\"code\": 10726,\"message\": \"Distinguished name component CN with value \\\"test.venafi.io\\\" is invalid\",\"args\": [\"CN\",\"test.venafi.io\",[\".*.example.com\",\".*.example.org\",\".*.example.net\",\".*.invalid\",\".*.local\",\".*.localhost\",\".*.test\"]]}]}") 37 errors, err := parseResponseErrors(data) 38 if err != nil { 39 t.Fatalf("err is not nil, err: %s", err) 40 } 41 42 if len(errors) != 1 { 43 t.Fatalf("ParseResponseErrors returned incorrect error count. Expected: 1 Actual: %d", len(errors)) 44 } 45 if errors[0].Code != 10726 { 46 t.Fatalf("ParseResponseErrors returned incorrect code. Expected: 10726 Actual: %d", errors[0].Code) 47 } 48 }