<commit_before>package storage_test

import (
	"github.com/MatthewHartstonge/storage"
	"github.com/stretchr/testify/assert"
	"testing"
)

// TestConnectionURISingleHostNoCredentials ensures a correctly formed mongo connection URI is generated for connecting
// to an unsecured mongo host.
func TestConnectionURISingleHostNoCredentials(t *testing.T) {
	expected := "mongodb://127.0.0.1:27017/test"
	cfg := &storage.Config{
		Hostname:     "127.0.0.1",
		Hostnames:    nil,
		Port:         27017,
		DatabaseName: "test",

		// Credential Access
		Username: "",
		Password: "",

		// Replica Set
		Replset: "",
	}
	got := storage.ConnectionURI(cfg)
	assert.EqualValues(t, expected, got)
}

// TestConnectionURISingleHostCredentials ensures a correctly formed mongo connection URI is generated for connecting
// to a single mongo host with database access credentials.
func TestConnectionURISingleHostCredentials(t *testing.T) {
	expected := "mongodb://testuser:testuserpass@127.0.0.1:27017/test"
	cfg := &storage.Config{
		Hostname:     "127.0.0.1",
		Hostnames:    nil,
		Port:         27017,
		DatabaseName: "test",

		// Credential Access
		Username: "testuser",
		Password: "<PASSWORD>",

		// Replica Set
		Replset: "",
	}
	got := storage.ConnectionURI(cfg)
	assert.EqualValues(t, expected, got)
}

// TestConnectionURIReplSetNoCredentials ensures a correctly formed mongo connection URI is generated for connecting
// to an unsecured mongo replica set.
func TestConnectionURIReplSetNoCredentials(t *testing.T) {
	expected := "mongodb://127.0.0.1:27017,127.0.1.1:27017,127.0.2.1:27017/test?replicaSet=sr0"
	cfg := &storage.Config{
		Hostname:     "",
		Hostnames:    []string{"127.0.0.1", "127.0.1.1", "127.0.2.1"},
		Port:         27017,
		DatabaseName: "test",

		// Credential Access
		Username: "",
		Password: "",

		// Replica Set
		Replset: "sr0",
	}
	got := storage.ConnectionURI(cfg)
	assert.EqualValues(t, expected, got)
}

// TestConnectionURIReplSetCredentials ensures a correctly formed mongo connection URI is generated for connecting
// to a mongo replica set with database access credentials.
func TestConnectionURIReplSetCredentials(t *testing.T) {
	expected := "mongodb://testuser:testuserpass@127.0.0.1:27017,127.0.1.1:27017,127.0.2.1:27017/test?replicaSet=sr0"
	cfg := &storage.Config{
		Hostname:     "",
		Hostnames:    []string{"127.0.0.1", "127.0.1.1", "127.0.2.1"},
		Port:         27017,
		DatabaseName: "test",

		// Credential Access
		Username: "testuser",
		Password: "<PASSWORD>",

		// Replica Set
		Replset: "sr0",
	}
	got := storage.ConnectionURI(cfg)
	assert.EqualValues(t, expected, got)
}

// TestNewDatastoreErrorsWithBadConfig ensures the underlying lib used for Mongo creates an error
func TestNewDatastoreErrorsWithBadConfig(t *testing.T) {
	cfg := &storage.Config{
		Hostname:     "notevenanaddress",
		Port:         27666,
		DatabaseName: "lulz",
	}
	conn, err := storage.NewDatastore(cfg)
	assert.Nil(t, conn)
	assert.NotNil(t, err)
	assert.Error(t, err)
}
<commit_msg>:arrow_up: Storage: Ensures the Default config is one that allows connection to an unauthenticated locally hosted mongo instance.<commit_after>package storage_test

import (
	"github.com/MatthewHartstonge/storage"
	"github.com/stretchr/testify/assert"
	"testing"
)

// TestDefaultConfig ensures the Default config is one that allows connection to an unauthenticated locally hosted
// mongo instance.
func TestDefaultConfig(t *testing.T) {
	expected := &storage.Config{
		Hostname:     "127.0.0.1",
		Port:         27017,
		DatabaseName: "storageTest",
	}
	got := storage.DefaultConfig()
	assert.NotNil(t, got)
	assert.ObjectsAreEqualValues(expected, got)
}

// TestConnectionURISingleHostNoCredentials ensures a correctly formed mongo connection URI is generated for connecting
// to an unsecured mongo host.
func TestConnectionURISingleHostNoCredentials(t *testing.T) {
	expected := "mongodb://127.0.0.1:27017/test"
	cfg := &storage.Config{
		Hostname:     "127.0.0.1",
		Hostnames:    nil,
		Port:         27017,
		DatabaseName: "test",

		// Credential Access
		Username: "",
		Password: "",

		// Replica Set
		Replset: "",
	}
	got := storage.ConnectionURI(cfg)
	assert.EqualValues(t, expected, got)
}

// TestConnectionURISingleHostCredentials ensures a correctly formed mongo connection URI is generated for connecting
// to a single mongo host with database access credentials.
func TestConnectionURISingleHostCredentials(t *testing.T) {
	expected := "mongodb://testuser:testuserpass@127.0.0.1:27017/test"
	cfg := &storage.Config{
		Hostname:     "127.0.0.1",
		Hostnames:    nil,
		Port:         27017,
		DatabaseName: "test",

		// Credential Access
		Username: "testuser",
		Password: "<PASSWORD>",

		// Replica Set
		Replset: "",
	}
	got := storage.ConnectionURI(cfg)
	assert.EqualValues(t, expected, got)
}

// TestConnectionURIReplSetNoCredentials ensures a correctly formed mongo connection URI is generated for connecting
// to an unsecured mongo replica set.
func TestConnectionURIReplSetNoCredentials(t *testing.T) {
	expected := "mongodb://127.0.0.1:27017,127.0.1.1:27017,127.0.2.1:27017/test?replicaSet=sr0"
	cfg := &storage.Config{
		Hostname:     "",
		Hostnames:    []string{"127.0.0.1", "127.0.1.1", "127.0.2.1"},
		Port:         27017,
		DatabaseName: "test",

		// Credential Access
		Username: "",
		Password: "",

		// Replica Set
		Replset: "sr0",
	}
	got := storage.ConnectionURI(cfg)
	assert.EqualValues(t, expected, got)
}

// TestConnectionURIReplSetCredentials ensures a correctly formed mongo connection URI is generated for connecting
// to a mongo replica set with database access credentials.
func TestConnectionURIReplSetCredentials(t *testing.T) {
	expected := "mongodb://testuser:testuserpass@127.0.0.1:27017,127.0.1.1:27017,127.0.2.1:27017/test?replicaSet=sr0"
	cfg := &storage.Config{
		Hostname:     "",
		Hostnames:    []string{"127.0.0.1", "127.0.1.1", "127.0.2.1"},
		Port:         27017,
		DatabaseName: "test",

		// Credential Access
		Username: "testuser",
		Password: "<PASSWORD>",

		// Replica Set
		Replset: "sr0",
	}
	got := storage.ConnectionURI(cfg)
	assert.EqualValues(t, expected, got)
}

// TestNewDatastoreErrorsWithBadConfig ensures the underlying lib used for Mongo creates an error
func TestNewDatastoreErrorsWithBadConfig(t *testing.T) {
	cfg := &storage.Config{
		Hostname:     "notevenanaddress",
		Port:         27666,
		DatabaseName: "lulz",
	}
	conn, err := storage.NewDatastore(cfg)
	assert.Nil(t, conn)
	assert.NotNil(t, err)
	assert.Error(t, err)
}

{'fraction_non_alphanumeric': 0.13199755276843073, 'fraction_numerical': 0.05215662282043439, 'mean_word_length': 3.9954163483575247, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 33, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5774110', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2233, 'n_words': 511}