package main

import (
	"strconv"
	"testing"
	"time"

	"gitlab.com/khanzf/fedilogue/shared"
)

func TestStatusReport_empty_run(t *testing.T) {
	// Empty Instances run
	StatusReport()
}

func TestStatusReport_full_content(t *testing.T) {
	defer func() {
		runninginstances = map[string]shared.RunningInstance{}
	}()
	runninginstances = make(map[string]shared.RunningInstance)

	identifier := 0
	var endpoint string

	test_instance_types := []string{"pleroma", "mastodon", "unknown", ""}
	test_statuses := []int{shared.NEW_INSTANCE, shared.RUNNING, shared.UNAUTHORIZED, shared.FORBIDDEN, shared.NOT_FOUND, shared.UNPROCESSABLE_ENTITY, shared.TOOMANYREQUESTS, shared.INTERNAL_ERROR, shared.CLIENT_ISSUE, shared.ONION_PROTOCOL, shared.BAD_RESPONSE, shared.BAD_NODEINFO, shared.UNSUPPORTED_INSTANCE, shared.STREAM_ENDED, shared.KEEPALIVE}

	for _, test_instance_type := range test_instance_types {
		for _, test_status := range test_statuses {
			a := shared.RunningInstance{}
			endpoint = "endpoint" + strconv.Itoa(identifier) + ".test.com"
			a.Client = BuildClient(endpoint)
			a.Status = test_status
			a.Recentactivities = shared.NewUniqueFifo(10)
			a.Recentactors = shared.NewUniqueFifo(10)
			a.Software = test_instance_type
			a.Version = "0." + strconv.Itoa(identifier)
			a.LastRun = time.Now().Format(time.RFC3339)
			runninginstances[endpoint] = a
			identifier = identifier + 1
		}
	}

	StatusReport()

}