This file is indexed.

/usr/share/gocode/src/github.com/JamesClonk/vultr/lib/snapshots_test.go is in golang-github-jamesclonk-vultr-dev 1.13.0-1.

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
106
107
108
109
110
111
112
package lib

import (
	"net/http"
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_Snapshots_GetSnapshots_Error(t *testing.T) {
	server, client := getTestServerAndClient(http.StatusNotAcceptable, `{error}`)
	defer server.Close()

	snapshots, err := client.GetSnapshots()
	assert.Nil(t, snapshots)
	if assert.NotNil(t, err) {
		assert.Equal(t, `{error}`, err.Error())
	}
}

func Test_Snapshots_GetSnapshots_NoSnapshots(t *testing.T) {
	server, client := getTestServerAndClient(http.StatusOK, `[]`)
	defer server.Close()

	snapshots, err := client.GetSnapshots()
	if err != nil {
		t.Error(err)
	}
	assert.Nil(t, snapshots)
}

func Test_Snapshots_GetSnapshots_OK(t *testing.T) {
	server, client := getTestServerAndClient(http.StatusOK, `{
"5359435d28b9a": {"SNAPSHOTID": "5359435d28b9a","date_created": "2014-04-18 12:40:40",
    "description": "test snapshot","size": "42949672960","status": "complete"},
"5359435dc1df3": {"SNAPSHOTID": "5359435dc1df3","date_created": "2014-04-22 16:11:46",
    "description": "a","size": "10000000","status": "incomplete"}}`)
	defer server.Close()

	snapshots, err := client.GetSnapshots()
	if err != nil {
		t.Error(err)
	}
	if assert.NotNil(t, snapshots) {
		assert.Equal(t, 2, len(snapshots))

		assert.Equal(t, "5359435dc1df3", snapshots[0].ID)
		assert.Equal(t, "a", snapshots[0].Description)
		assert.Equal(t, "10000000", snapshots[0].Size)
		assert.Equal(t, "incomplete", snapshots[0].Status)
		assert.Equal(t, "2014-04-22 16:11:46", snapshots[0].Created)

		assert.Equal(t, "5359435d28b9a", snapshots[1].ID)
		assert.Equal(t, "test snapshot", snapshots[1].Description)
		assert.Equal(t, "42949672960", snapshots[1].Size)
		assert.Equal(t, "complete", snapshots[1].Status)
		assert.Equal(t, "2014-04-18 12:40:40", snapshots[1].Created)
	}
}

func Test_Snapshots_CreateSnapshot_Error(t *testing.T) {
	server, client := getTestServerAndClient(http.StatusNotAcceptable, `{error}`)
	defer server.Close()

	snapshot, err := client.CreateSnapshot("12345", "test snappy")
	assert.Equal(t, Snapshot{}, snapshot)
	if assert.NotNil(t, err) {
		assert.Equal(t, `{error}`, err.Error())
	}
}

func Test_Snapshots_CreateSnapshot_NoSnapshot(t *testing.T) {
	server, client := getTestServerAndClient(http.StatusOK, `[]`)
	defer server.Close()

	snapshot, err := client.CreateSnapshot("12345", "test snappy")
	if err != nil {
		t.Error(err)
	}
	assert.Equal(t, "", snapshot.ID)
}

func Test_Snapshots_CreateSnapshot_OK(t *testing.T) {
	server, client := getTestServerAndClient(http.StatusOK, `{"SNAPSHOTID": "544e52f31c706"}`)
	defer server.Close()

	snapshot, err := client.CreateSnapshot("12345", "test snappy")
	if err != nil {
		t.Error(err)
	}
	if assert.NotNil(t, snapshot) {
		assert.Equal(t, "544e52f31c706", snapshot.ID)
		assert.Equal(t, "test snappy", snapshot.Description)
	}
}

func Test_Snapshots_DeleteSnapshot_Error(t *testing.T) {
	server, client := getTestServerAndClient(http.StatusNotAcceptable, `{error}`)
	defer server.Close()

	err := client.DeleteSnapshot("id-1")
	if assert.NotNil(t, err) {
		assert.Equal(t, `{error}`, err.Error())
	}
}

func Test_Snapshots_DeleteSnapshot_OK(t *testing.T) {
	server, client := getTestServerAndClient(http.StatusOK, `{no-response?!}`)
	defer server.Close()

	assert.Nil(t, client.DeleteSnapshot("id-1"))
}