Exemple #1
0
func TestNSSErrors(t *testing.T) {
	Convey("Given an NSS server", t, func() {
		server := nss.New(sys.DefaultExecutor)

		Convey("When queried with a wrong database", func() {
			var (
				db  nss.Database = "InvalidDatabase"
				key string       = "some_entry"
			)

			Convey("It should return an error message containing: Unknown database", func() {
				_, err := server.GetEntryFrom(db, key)
				So(err, ShouldNotBeNil)

				So(err.Error(), ShouldContainSubstring, "Unknown database")
			})
		})

		Convey("When queried with a non-existent user", func() {
			var (
				db  nss.Database = nss.UserDatabase
				key string       = rand.String(10)
			)

			Convey("It should return an error message containing: Key could not be found", func() {
				_, err := server.GetEntryFrom(db, key)

				So(err, ShouldNotBeNil)

				So(err.Error(), ShouldContainSubstring, "Key could not be found")
			})
		})
	})
}
Exemple #2
0
func UniqueName(dir, prefix string) (string, error) {
	for i, retries := 0, 100; i < retries; i++ {
		suffix := rand.String(8)

		fname := filepath.Join(dir, prefix+suffix)

		if _, err := os.Lstat(fname); err != nil {
			if os.IsNotExist(err) {
				return fname, nil
			} else {
				return "", err
			}
		}
	}

	return "", fmt.Errorf("file name collision after every retry")
}