mirror of
https://github.com/bettercap/bettercap
synced 2025-07-31 04:00:09 -07:00
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package network
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func buildExampleMeta() *Meta {
|
|
return NewMeta()
|
|
}
|
|
|
|
func TestNewMeta(t *testing.T) {
|
|
exp := len(Meta{}.m)
|
|
got := len(NewMeta().m)
|
|
if got != exp {
|
|
t.Fatalf("expected '%v', got '%v'", exp, got)
|
|
}
|
|
}
|
|
|
|
func TestMetaMarshalJSON(t *testing.T) {
|
|
_, err := buildExampleMeta().MarshalJSON()
|
|
if err != nil {
|
|
t.Error("unable to marshal JSON from meta struct")
|
|
}
|
|
}
|
|
|
|
func TestMetaSet(t *testing.T) {
|
|
example := buildExampleMeta()
|
|
example.Set("picat", "<3")
|
|
if example.m["picat"] != "<3" {
|
|
t.Error("unable to set meta data in struct")
|
|
}
|
|
}
|
|
|
|
// TODO document what this does, not too clear,
|
|
// at least for me today lolololol
|
|
func TestMetaGetIntsWith(t *testing.T) {
|
|
example := buildExampleMeta()
|
|
example.m["picat"] = "3,"
|
|
|
|
exp := []int{4, 3}
|
|
got := example.GetIntsWith("picat", 4, false)
|
|
|
|
if exp[0] != got[0] {
|
|
t.Fatalf("expected '%v', got '%v'", exp, got)
|
|
}
|
|
}
|
|
|
|
func TestMetaSetInts(t *testing.T) {
|
|
example := buildExampleMeta()
|
|
example.SetInts("picat", []int{0, 1})
|
|
|
|
exp := strings.Join([]string{"0", "1"}, ",")
|
|
got := example.m["picat"]
|
|
|
|
if exp != got {
|
|
t.Fatalf("expected '%v', got '%v'", exp, got)
|
|
}
|
|
}
|