GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

handlers_test.go 565 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package main

import (
	"fmt"
	"testing"
	"time"
)

func TestCreateJsonResult(t *testing.T) {

	expected := `{"functional":false,"error":"test","time":1}`
	now := time.Now()
	then := now.Add(time.Duration(-1) * time.Second)
	json := createJsonResult(fmt.Errorf("test"), then)
	if json != expected {
		t.Errorf("Got unexpected JSON: %s", json)
	}

19
	expected = `{"functional":true,"time":1}`
20 21 22 23 24 25 26
	now = time.Now()
	then = now.Add(time.Duration(-1) * time.Second)
	json = createJsonResult(nil, then)
	if json != expected {
		t.Errorf("Got unexpected JSON: %s", json)
	}
}