1// Copyright 2020 Google LLC 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// https://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 15package git 16 17import ( 18 "io/ioutil" 19 "os" 20 "path" 21 "reflect" 22 "testing" 23) 24 25func TestList(t *testing.T) { 26 testCodebaseDir, err := ioutil.TempDir("", "codebase") 27 if err != nil { 28 t.Error(err) 29 } 30 if err = os.Mkdir(path.Join(testCodebaseDir, ".repo"), os.ModePerm); err != nil { 31 t.Error(err) 32 } 33 listContents := []byte( 34 "path/to/project1\n" + 35 "path/to/project2\n" + 36 "path/to/project3") 37 listFile := path.Join(testCodebaseDir, ".repo/project.list") 38 if err = ioutil.WriteFile(listFile, listContents, os.ModePerm); err != nil { 39 t.Error(err) 40 } 41 lister := NewRepoLister() 42 projectList, err := lister.List(testCodebaseDir) 43 if err != nil { 44 t.Error(err) 45 } 46 expectedList := []string{ 47 ".repo", 48 "path/to/project1", 49 "path/to/project2", 50 "path/to/project3", 51 } 52 if !reflect.DeepEqual(projectList, expectedList) { 53 t.Errorf("Got list %v but expected %v", projectList, expectedList) 54 } 55} 56