diff --git a/internal/database/actions_test.go b/internal/database/actions_test.go index 8c7e770..0da42c5 100644 --- a/internal/database/actions_test.go +++ b/internal/database/actions_test.go @@ -6,7 +6,6 @@ import ( "os" "testing" - "github.com/apex/log" "github.com/ooni/probe-cli/utils" ) @@ -15,8 +14,7 @@ func TestMeasurementWorkflow(t *testing.T) { if err != nil { t.Fatal(err) } - log.Infof("%s", tmpfile.Name()) - //defer os.Remove(tmpfile.Name()) + defer os.Remove(tmpfile.Name()) tmpdir, err := ioutil.TempDir("", "oonitest") if err != nil { @@ -26,7 +24,7 @@ func TestMeasurementWorkflow(t *testing.T) { sess, err := Connect(tmpfile.Name()) if err != nil { - t.Error(err) + t.Fatal(err) } location := utils.LocationInfo{ @@ -84,3 +82,36 @@ func TestMeasurementWorkflow(t *testing.T) { t.Error("network_type should be wifi") } } + +func TestURLCreation(t *testing.T) { + tmpfile, err := ioutil.TempFile("", "dbtest") + if err != nil { + t.Fatal(err) + } + defer os.Remove(tmpfile.Name()) + + tmpdir, err := ioutil.TempDir("", "oonitest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpdir) + + sess, err := Connect(tmpfile.Name()) + if err != nil { + t.Fatal(err) + } + + newID1, err := CreateOrUpdateURL(sess, "https://google.com", "SRCH", "XX") + if err != nil { + t.Fatal(err) + } + + newID2, err := CreateOrUpdateURL(sess, "https://google.com", "GMB", "XX") + if err != nil { + t.Fatal(err) + } + + if newID2 != newID1 { + t.Error("inserting the same URL with different category code should produce the same result") + } +}