helpers_test.go (1749B)
1 package damlib 2 3 /* 4 * Copyright (c) 2018 Dyne.org Foundation 5 * tor-dam is written and maintained by Ivan Jelincic <parazyd@dyne.org> 6 * 7 * This file is part of tor-dam 8 * 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU Affero General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Affero General Public License for more details. 18 * 19 * You should have received a copy of the GNU Affero General Public License 20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 import ( 24 "testing" 25 ) 26 27 func TestStringInSlice(t *testing.T) { 28 sl := []string{"foo", "bar", "baz"} 29 if !(StringInSlice("bar", sl)) { 30 t.Fatal("\"bar\" should be in the slice.") 31 } 32 if StringInSlice("kek", sl) { 33 t.Fatal("\"kek\" should not be in the slice.") 34 } 35 } 36 37 func TestGzipEncode(t *testing.T) { 38 data := "Compress this string" 39 if _, err := GzipEncode([]byte(data)); err != nil { 40 t.Fatal(err) 41 } 42 } 43 44 func TestParseDirs(t *testing.T) { 45 var sl []string 46 data := `DIR:gphjf5g3d5ywehwrd7cv3czymtdc6ha67bqplxwbspx7tioxt7gxqiid.onion 47 # Some random data 48 DIR:vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion` 49 50 sl = ParseDirs(sl, []byte(data)) 51 52 if len(sl) != 2 { 53 t.Fatal("Length of slice is not 2.") 54 } 55 } 56 57 func TestGenRandomASCII(t *testing.T) { 58 res, err := GenRandomASCII(64) 59 if err != nil { 60 t.Fatal(err) 61 } 62 if len(res) != 64 { 63 t.Fatal("Length of ASCII string is not 64.") 64 } 65 }