github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/pkg/group/group_test.go (about) 1 // Copyright 2015 The rkt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package group 16 17 import ( 18 "reflect" 19 "testing" 20 ) 21 22 func TestParseGroupLine(t *testing.T) { 23 tests := []struct { 24 line string 25 groupLine *Group 26 shouldSucceed bool 27 }{ 28 { 29 "ftp:x:1:", 30 &Group{ 31 "ftp", 32 "x", 33 1, 34 []string{}, 35 }, 36 true, 37 }, 38 { 39 "u1:xxx:12:wheel,users", 40 &Group{ 41 "u1", 42 "xxx", 43 12, 44 []string{"wheel", "users"}, 45 }, 46 true, 47 }, 48 { 49 "uerr:x:", 50 nil, 51 false, 52 }, 53 { 54 "", 55 nil, 56 false, 57 }, 58 { 59 "u1:xxx:12:wheel,users:extra:stuff", 60 &Group{ 61 "u1", 62 "xxx", 63 12, 64 []string{"wheel", "users"}, 65 }, 66 true, 67 }, 68 } 69 70 for i, tt := range tests { 71 g, err := parseGroupLine(tt.line) 72 if err != nil { 73 if tt.shouldSucceed { 74 t.Errorf("#%d: parsing line %q failed unexpectedly", i, tt.line) 75 } 76 continue 77 } 78 if !reflect.DeepEqual(g, tt.groupLine) { 79 t.Errorf("#%d: got group %v, want group %v", i, g, tt.groupLine) 80 } 81 } 82 }