<commit_before>package main

import (
	"fmt"
	"testing"

	. "github.com/smartystreets/goconvey/convey"
	nagios "source.datanerd.us/site-engineering/go_nagios"
)

var jsonFromApi []byte = []byte(
	`{
		"DriverStatus": [
			["Data Space Used", "20.0 mb"],
			["Data Space Total", "1000.0 mb"],
			["Metadata Space Used", "15.0 mb"],
			["Metadata Space Total", "200.0 mb"]
		]
	}`,
)


type stubFetcher struct{}

func (fetcher stubFetcher) Fetch(url string) ([]byte, error) {
	return jsonFromApi, nil
}

func TestFloat64String(t *testing.T) {
	Convey("Converts a float to a formatted string with no decimals", t, func() {
		So(float64String(1.2), ShouldEqual, "1")
	})
}

func TestMegabytesFloat64(t *testing.T) {
	Convey("Extracts the float from a Docker megabytes measurement string", t, func() {
		result, _ := megabytesFloat64("1024.05 Mb")
		So(result, ShouldEqual, 1024.05)
	})

	Convey("Returns an error when not parseable", t, func() {
		_, err := megabytesFloat64("1024.05 Mb")
		So(err, ShouldBeNil)
	})
}

func TestFindDriverStatus(t *testing.T) {
	driverStatuses := [][]string{
		[]string{"Key", "Value"},
		[]string{"Key2", "Value2"},
	}

	Convey("Looks up values from a slice by the first element", t, func() {
		So(findDriverStatus("Key", driverStatuses), ShouldEqual, "Value")
		So(findDriverStatus("Key2", driverStatuses), ShouldEqual, "Value2")
	})

	Convey("Returns empty on failure", t, func() {
		So(findDriverStatus("KeyFoo", driverStatuses), ShouldEqual, "")
	})
}

func TestPopulateDriverInfo(t *testing.T) {
	Convey("Correctly parses the JSON and populates the DockerInfo", t, func() {
		var info DockerInfo
		err := populateInfo(jsonFromApi, &info)<commit_msg>Test what the test actually says it's testing.<commit_after>package main

import (
	"fmt"
	"testing"

	. "github.com/smartystreets/goconvey/convey"
	nagios "source.datanerd.us/site-engineering/go_nagios"
)

var jsonFromApi []byte = []byte(
	`{
		"DriverStatus": [
			["Data Space Used", "20.0 mb"],
			["Data Space Total", "1000.0 mb"],
			["Metadata Space Used", "15.0 mb"],
			["Metadata Space Total", "200.0 mb"]
		]
	}`,
)


type stubFetcher struct{}

func (fetcher stubFetcher) Fetch(url string) ([]byte, error) {
	return jsonFromApi, nil
}

func TestFloat64String(t *testing.T) {
	Convey("Converts a float to a formatted string with no decimals", t, func() {
		So(float64String(1.2), ShouldEqual, "1")
	})
}

func TestMegabytesFloat64(t *testing.T) {
	Convey("Extracts the float from a Docker megabytes measurement string", t, func() {
		result, _ := megabytesFloat64("1024.05 Mb")
		So(result, ShouldEqual, 1024.05)
	})

	Convey("Returns an error when not parseable", t, func() {
		_, err := megabytesFloat64("1024.05mb")
		So(err.Error(), ShouldContainSubstring, "invalid syntax")
	})
}

func TestFindDriverStatus(t *testing.T) {
	driverStatuses := [][]string{
		[]string{"Key", "Value"},
		[]string{"Key2", "Value2"},
	}

	Convey("Looks up values from a slice by the first element", t, func() {
		So(findDriverStatus("Key", driverStatuses), ShouldEqual, "Value")
		So(findDriverStatus("Key2", driverStatuses), ShouldEqual, "Value2")
	})

	Convey("Returns empty on failure", t, func() {
		So(findDriverStatus("KeyFoo", driverStatuses), ShouldEqual, "")
	})
}

func TestPopulateDriverInfo(t *testing.T) {
	Convey("Correctly parses the JSON and populates the DockerInfo", t, func() {
		var info DockerInfo
		err := populateInfo(jsonFromApi, &info)
{'fraction_non_alphanumeric': 0.15944137329066047, 'fraction_numerical': 0.02909514111143439, 'mean_word_length': 4.917383820998279, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '3264891', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1207, 'n_words': 315}