This file is indexed.

/usr/share/gocode/src/github.com/constabulary/gb/internal/vendor/manifest_test.go is in golang-github-constabulary-gb-dev 0.4.4-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
package vendor

import (
	"bytes"
	"os"
	"path/filepath"
	"testing"
)

func mktemp(t *testing.T) string {
	s, err := mktmp()
	if err != nil {
		t.Fatal(err)
	}
	return s
}

func assertNotExists(t *testing.T, path string) {
	_, err := os.Stat(path)
	if err == nil || !os.IsNotExist(err) {
		t.Fatalf("expected %q to be not found, got %v", path, err)
	}
}

func assertExists(t *testing.T, path string) {
	_, err := os.Stat(path)
	if err != nil {
		t.Fatalf("expected %q to be found, got %v", path, err)
	}
}

func TestManifest(t *testing.T) {
	root := mktemp(t)
	defer os.RemoveAll(root)

	mf := filepath.Join(root, "vendor")

	// check that reading an non existant manifest
	// does not return an error
	m, err := ReadManifest(mf)
	if err != nil {
		t.Fatalf("reading a non existant manifest should not fail: %v", err)
	}

	// check that no manifest file was created
	assertNotExists(t, mf)

	// add a dep
	m.Dependencies = append(m.Dependencies, Dependency{
		Importpath: "github.com/foo/bar/baz",
		Repository: "https://github.com/foo/bar",
		Revision:   "cafebad",
		Branch:     "master",
		Path:       "/baz",
	})

	// write it back
	if err := WriteManifest(mf, m); err != nil {
		t.Fatalf("WriteManifest failed: %v", err)
	}

	// check the manifest was written
	assertExists(t, mf)

	// remove it
	m.Dependencies = nil
	if err := WriteManifest(mf, m); err != nil {
		t.Fatalf("WriteManifest failed: %v", err)
	}

	// check that no manifest file was removed
	assertNotExists(t, mf)
}

func TestEmptyPathIsNotWritten(t *testing.T) {
	m := Manifest{
		Version: 0,
		Dependencies: []Dependency{{
			Importpath: "github.com/foo/bar",
			Repository: "https://github.com/foo/bar",
			Revision:   "abcdef",
			Branch:     "master",
		}},
	}
	var buf bytes.Buffer
	if err := writeManifest(&buf, &m); err != nil {
		t.Fatal(err)
	}
	want := `{
	"version": 0,
	"dependencies": [
		{
			"importpath": "github.com/foo/bar",
			"repository": "https://github.com/foo/bar",
			"revision": "abcdef",
			"branch": "master"
		}
	]
}
`
	got := buf.String()
	if want != got {
		t.Fatalf("want: %s, got %s", want, got)
	}
}