Skip to content

Commit

Permalink
test: added tests for GetBaseIp
Browse files Browse the repository at this point in the history
tarithj committed Feb 2, 2021
1 parent 652f599 commit 6324a7a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions utils/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package utils

import (
"testing"
)

func TestGetBaseIp(t *testing.T) {
var tests = []struct {
addrWithPort string
ipAddr string
}{
{"localhost:8080", "localhost"},
{"192.168.8.1:8989", "192.168.8.1"},
{"192.168.8.200:8076", "192.168.8.200"},
}

for _, value := range tests {
if a := GetBaseIp(value.addrWithPort); a != value.ipAddr {
t.Errorf("ipaddress not eqal to GetBaseIp result: %s != %s", a, value.ipAddr)
}
}
}

func BenchmarkGetBaseIp(b *testing.B) {
var p = "localhost:8080"

for i := 0; i < b.N; i++ {
_ = GetBaseIp(p)
}

}

0 comments on commit 6324a7a

Please sign in to comment.