| 1 | package testsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/ |
| 2 | |
| 3 | import ( |
| 4 | "io/ioutilscip-go gomod github.com/golang/go/src go1.15 `io/ioutil`/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.15 testing/" |
| 6 | |
| 7 | "github.com/cretz/bine/controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/" |
| 8 | ) |
| 9 | |
| 10 | func TestGetSetAndResetConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestGetSetAndResetConf().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 11 | ctx := NewTestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/NewTestContext().(t, nil) |
| 12 | defer ctx.Closescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Close().() |
| 13 | // Simple get conf |
| 14 | assertConfVals := func(val string) { |
| 15 | entries, err := ctx.Controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Control..GetConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#GetConf().("LogMessageDomains", "ProtocolWarnings") |
| 16 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 17 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Len().(entries, 2) |
| 18 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Containsscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Contains().(entries, controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/.NewKeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/NewKeyVal().("LogMessageDomains", val)) |
| 19 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Containsscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Contains().(entries, controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/.NewKeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/NewKeyVal().("ProtocolWarnings", val)) |
| 20 | } |
| 21 | assertConfVals("0") |
| 22 | // Change em both to 1 |
| 23 | one := "1" |
| 24 | err := ctx.Controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Control..SetConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#SetConf().(controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/.KeyValsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVals().("LogMessageDomains", "1", "ProtocolWarnings", "1")...) |
| 25 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 26 | // Check again |
| 27 | assertConfVals(one) |
| 28 | // Reset em both |
| 29 | err = ctx.Controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Control..ResetConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#ResetConf().(controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/.KeyValsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVals().("LogMessageDomains", "", "ProtocolWarnings", "")...) |
| 30 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 31 | // Make sure both back to zero |
| 32 | assertConfVals("0") |
| 33 | } |
| 34 | |
| 35 | func TestLoadConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestLoadConf().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 36 | ctx := NewTestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/NewTestContext().(t, nil) |
| 37 | defer ctx.Closescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Close().() |
| 38 | // Get entire conf text |
| 39 | vals, err := ctx.Controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Control..GetInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#GetInfo().("config-text") |
| 40 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 41 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Len().(vals, 1) |
| 42 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Equal().("config-text", vals[0].Keyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Key.) |
| 43 | confText := vals[0].Valscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Val. |
| 44 | // Append new conf val and load |
| 45 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NotContainsscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NotContains().(confText, "LogMessageDomains") |
| 46 | confText += "\r\nLogMessageDomains 1" |
| 47 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(ctx.Controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Control..LoadConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#LoadConf().(confText)) |
| 48 | // Check the new val |
| 49 | vals, err = ctx.Controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Control..GetInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#GetInfo().("config-text") |
| 50 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 51 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Len().(vals, 1) |
| 52 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Equal().("config-text", vals[0].Keyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Key.) |
| 53 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Containsscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Contains().(vals[0].Valscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Val., "LogMessageDomains 1") |
| 54 | } |
| 55 | |
| 56 | func TestSaveConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestSaveConf().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 57 | ctx := NewTestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/NewTestContext().(t, nil) |
| 58 | defer ctx.Closescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Close().() |
| 59 | // Get conf filename |
| 60 | vals, err := ctx.Controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Control..GetInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#GetInfo().("config-file") |
| 61 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 62 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Len().(vals, 1) |
| 63 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Equal().("config-file", vals[0].Keyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Key.) |
| 64 | confFile := vals[0].Valscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Val. |
| 65 | // Save it |
| 66 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(ctx.Controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Control..SaveConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#SaveConf().(false)) |
| 67 | // Read and make sure, say, the DataDirectory is accurate |
| 68 | confText, err := ioutilscip-go gomod github.com/golang/go/src go1.15 `io/ioutil`/.ReadFilescip-go gomod github.com/golang/go/src go1.15 `io/ioutil`/ReadFile().(confFile) |
| 69 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 70 | ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Containsscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Contains().(string(confText), "DataDirectory "+ctx.DataDirscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#DataDir.) |
| 71 | } |