<commit_before>package unifiexporter

import (
	"regexp"
	"strings"
	"testing"

	"github.com/mdlayher/unifi"
)

func TestStationCollector(t *testing.T) {
	var tests = []struct {
		desc    string
		input   string
		sites   []*unifi.Site
		matches []*regexp.Regexp
	}{
		{
			desc: "one station, one site",
			input: strings.TrimSpace(`
{
	"data": [
		{
			"_id": "abcdef",
			"ap_mac": "a0:a0:a0:a0:a0:a0",
			"mac": "de:ad:be:ef:de:ad",
			"hostname": "foo",
			"noise": -110,
			"rssi": 40,
			"rx_bytes": 10,
			"rx_packets": 1,
			"tx_bytes": 20,
			"tx_packets": 2
		}
	]
}
`),
			matches: []*regexp.Regexp{
				regexp.MustCompile(`unifi_stations{site="Default"} 1`),

				regexp.MustCompile(`unifi_stations_received_bytes_total{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 10`),
				regexp.MustCompile(`unifi_stations_transmitted_bytes_total{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 20`),

				regexp.MustCompile(`unifi_stations_received_packets_total{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 1`),
				regexp.MustCompile(`unifi_stations_transmitted_packets_total{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 2`),

				regexp.MustCompile(`unifi_stations_noise_dbm{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} -110`),
				regexp.MustCompile(`unifi_stations_rssi_dbm{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 40`),
			},
			sites: []*unifi.Site{{
				Name:        "default",
				Description: "Default",
			}},
		},
		{
			desc: "one wired station, one site",
			input: strings.TrimSpace(`
{
	"data": [
		{
			"_id": "abcdef",
			"mac": "de:ad:be:ef:de:ad",
			"hostname": "foo",
			"rx_bytes": 10,
			"rx_packets": 1,
			"tx_bytes": 20,
			"tx_packets": 2
		}
	]
}
`),
			matches: []*regexp.Regexp{
				regexp.MustCompile(`unifi_stations{site="Default"} 1`),<commit_msg>Fixing a stationcollector test that was broken by adding IsWired checking.<commit_after>package unifiexporter

import (
	"regexp"
	"strings"
	"testing"

	"github.com/mdlayher/unifi"
)

func TestStationCollector(t *testing.T) {
	var tests = []struct {
		desc    string
		input   string
		sites   []*unifi.Site
		matches []*regexp.Regexp
	}{
		{
			desc: "one station, one site",
			input: strings.TrimSpace(`
{
	"data": [
		{
			"_id": "abcdef",
			"ap_mac": "a0:a0:a0:a0:a0:a0",
			"mac": "de:ad:be:ef:de:ad",
			"hostname": "foo",
			"noise": -110,
			"rssi": 40,
			"rx_bytes": 10,
			"rx_packets": 1,
			"tx_bytes": 20,
			"tx_packets": 2
		}
	]
}
`),
			matches: []*regexp.Regexp{
				regexp.MustCompile(`unifi_stations{site="Default"} 1`),

				regexp.MustCompile(`unifi_stations_received_bytes_total{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 10`),
				regexp.MustCompile(`unifi_stations_transmitted_bytes_total{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 20`),

				regexp.MustCompile(`unifi_stations_received_packets_total{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 1`),
				regexp.MustCompile(`unifi_stations_transmitted_packets_total{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 2`),

				regexp.MustCompile(`unifi_stations_noise_dbm{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} -110`),
				regexp.MustCompile(`unifi_stations_rssi_dbm{ap_mac="a0:a0:a0:a0:a0:a0",hostname="foo",id="abcdef",site="Default",station_mac="de:ad:be:ef:de:ad"} 40`),
			},
			sites: []*unifi.Site{{
				Name:        "default",
				Description: "Default",
			}},
		},
		{
			desc: "one wired station, one site",
			input: strings.TrimSpace(`
{
	"data": [
		{
			"_id": "abcdef",
			"is_wired": true,
			"mac": "de:ad:be:ef:de:ad",
			"hostname": "foo",
			"rx_bytes": 10,
			"rx_packets": 1,
			"tx_bytes": 20,
			"tx_packets": 2
		}
	]
}
`),
			matches: []*regexp.Regexp{
				regexp.MustCompile(`unifi_stations{site="Default"} 1`),
{'fraction_non_alphanumeric': 0.2107571560480148, 'fraction_numerical': 0.0332409972299169, 'mean_word_length': 5.7387247278382585, 'pattern_counts': {'":': 39, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2232911', 'n_tokens_mistral': 2180, 'n_tokens_neox': 1905, 'n_words': 207}