github.com/jenkins-x/test-infra@v0.0.7/prow/config/org/org_test.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 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 org 18 19 import ( 20 "encoding/json" 21 "testing" 22 ) 23 24 func TestRepoPermissionLevel(t *testing.T) { 25 get := func(v RepoPermissionLevel) *RepoPermissionLevel { 26 return &v 27 } 28 cases := []struct { 29 input string 30 expected *RepoPermissionLevel 31 }{ 32 { 33 "admin", 34 get(Admin), 35 }, 36 { 37 "write", 38 get(Write), 39 }, 40 { 41 "read", 42 get(Read), 43 }, 44 { 45 "none", 46 get(None), 47 }, 48 { 49 "", 50 nil, 51 }, 52 { 53 "unknown", 54 nil, 55 }, 56 } 57 for _, tc := range cases { 58 var actual RepoPermissionLevel 59 err := json.Unmarshal([]byte("\""+tc.input+"\""), &actual) 60 switch { 61 case err == nil && tc.expected == nil: 62 t.Errorf("%s: failed to receive an error", tc.input) 63 case err != nil && tc.expected != nil: 64 t.Errorf("%s: unexpected error: %v", tc.input, err) 65 case err == nil && *tc.expected != actual: 66 t.Errorf("%s: actual %v != expected %v", tc.input, tc.expected, actual) 67 } 68 } 69 } 70 71 func TestPrivacy(t *testing.T) { 72 get := func(v Privacy) *Privacy { 73 return &v 74 } 75 cases := []struct { 76 input string 77 expected *Privacy 78 }{ 79 { 80 "secret", 81 get(Secret), 82 }, 83 { 84 "closed", 85 get(Closed), 86 }, 87 { 88 "", 89 nil, 90 }, 91 { 92 "unknown", 93 nil, 94 }, 95 } 96 for _, tc := range cases { 97 var actual Privacy 98 err := json.Unmarshal([]byte("\""+tc.input+"\""), &actual) 99 switch { 100 case err == nil && tc.expected == nil: 101 t.Errorf("%s: failed to receive an error", tc.input) 102 case err != nil && tc.expected != nil: 103 t.Errorf("%s: unexpected error: %v", tc.input, err) 104 case err == nil && *tc.expected != actual: 105 t.Errorf("%s: actual %v != expected %v", tc.input, tc.expected, actual) 106 } 107 } 108 }