fork of https://github.com/sourcegraph/zoekt
1// Copyright 2017 Google Inc. All rights reserved.
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
15package gitindex
16
17import (
18 "net/url"
19 "reflect"
20 "sort"
21 "testing"
22)
23
24func TestListReposNonExistent(t *testing.T) {
25 t.Parallel()
26
27 u, err := url.Parse("https://gerrit.googlesource.com/")
28 if err != nil {
29 t.Fatalf("url.Parse: %v", err)
30 }
31
32 rs, err := ListRepos("/doesnotexist", u)
33 if err == nil {
34 t.Fatalf("ListRepos(/doesnotexist): %v", rs)
35 }
36}
37
38func TestListRepos(t *testing.T) {
39 t.Parallel()
40
41 dir := t.TempDir()
42
43 if err := createSubmoduleRepo(dir); err != nil {
44 t.Fatalf("createSubmoduleRepo %v", err)
45 }
46
47 u, err := url.Parse("https://gerrit.googlesource.com/")
48 if err != nil {
49 t.Fatalf("url.Parse: %v", err)
50 }
51 rs, err := ListRepos(dir, u)
52 if err != nil {
53 t.Fatalf("ListRepos(%s): %v", u, err)
54 }
55
56 want := []string{
57 "gerrit.googlesource.com/adir.git",
58 "gerrit.googlesource.com/bdir.git",
59 "gerrit.googlesource.com/sub/bdir.git",
60 "gerrit.googlesource.com/team/scope/repoa.git",
61 "gerrit.googlesource.com/team/scope/repob.git",
62 }
63 sort.Strings(rs)
64
65 if !reflect.DeepEqual(rs, want) {
66 t.Fatalf("got %v, want %v", rs, want)
67 }
68}