<commit_before>package config

import "testing"

type fakeConfig struct {
	FieldOne string `servconf:"field_one,required"`
	FieldTwo string `servconf:"field_two"`
}

func TestServiceConfig(t *testing.T) {
	var confValidSC1 ServiceConfig
	var confValidSC2 ServiceConfig
	var confInvalidSC1 ServiceConfig
	confValidSC1 = map[string]interface{}{
		"field_one": "test1",
		"field_two": "test2",
	}
	confValidSC2 = map[string]interface{}{
		"field_one": "test1",
	}
	confInvalidSC1 = map[string]interface{}{
		"field_two": "test",
	}

	// TODO add other config structs with invalid tags and test it
	t.Run("AssignValidSC1", func(t *testing.T) {
		cfg := fakeConfig{}
		err := confValidSC1.Assign(&cfg)
		if err != nil {
			t.Errorf("Assign returned an unexpected error: %s", err)
		}
		if cfg.FieldOne != "test1" {
			t.Errorf("FieldOne value %q is not \"test1\"", cfg.FieldOne)
		}
		if cfg.FieldTwo != "test2" {
			t.Errorf("FieldTwo value %q is not \"test2\"", cfg.FieldTwo)
		}
	})
	t.Run("AssignValidSC2", func(t *testing.T) {
		cfg := fakeConfig{}
		err := confValidSC2.Assign(&cfg)
		if err != nil {
			t.Errorf("Assign returned an unexpected error: %s", err)
		}
		if cfg.FieldOne != "test1" {
			t.Errorf("FieldOne value %q is not \"test1\"", cfg.FieldOne)
		}
		if cfg.FieldTwo != "" {
			t.Errorf("FieldTwo value %q is not \"\"", cfg.FieldTwo)
		}
	})
	t.Run("AssignInvalidSC1", func(t *testing.T) {
		cfg := fakeConfig{}
		err := confInvalidSC1.Assign(&cfg)
		if err == nil {
			t.Errorf("Assign did not return an error when missing a required field")
			return
		}
		switch err.(type) {
		case *InvalidTagError:
			if err.(*InvalidTagError).NameTag == "field_one" {
				return
			}
		}
		t.Errorf("Assign returned an unexpected error: %s", err)
	})
}
<commit_msg>Diversify fakeConfig field types for better tests<commit_after>package config

import "testing"

type fakeConfig struct {
	FieldOne string `servconf:"field_one,required"`
	FieldTwo bool   `servconf:"field_two"`
}

func TestServiceConfig(t *testing.T) {
	var confValidSC1 ServiceConfig
	var confValidSC2 ServiceConfig
	var confInvalidSC1 ServiceConfig
	confValidSC1 = map[string]interface{}{
		"field_one": "test1",
		"field_two": true,
	}
	confValidSC2 = map[string]interface{}{
		"field_one": "test1",
	}
	confInvalidSC1 = map[string]interface{}{
		"field_two": true,
	}

	// TODO add other config structs with invalid tags and test it
	t.Run("AssignValidSC1", func(t *testing.T) {
		cfg := fakeConfig{}
		err := confValidSC1.Assign(&cfg)
		if err != nil {
			t.Errorf("Assign returned an unexpected error: %s", err)
		}
		if cfg.FieldOne != "test1" {
			t.Errorf("FieldOne value %q is not \"test1\"", cfg.FieldOne)
		}
		if !cfg.FieldTwo {
			t.Errorf("FieldTwo value %v is not true", cfg.FieldTwo)
		}
	})
	t.Run("AssignValidSC2", func(t *testing.T) {
		cfg := fakeConfig{}
		err := confValidSC2.Assign(&cfg)
		if err != nil {
			t.Errorf("Assign returned an unexpected error: %s", err)
		}
		if cfg.FieldOne != "test1" {
			t.Errorf("FieldOne value %q is not \"test1\"", cfg.FieldOne)
		}
		if cfg.FieldTwo {
			t.Errorf("FieldTwo value %v is not false", cfg.FieldTwo)
		}
	})
	t.Run("AssignInvalidSC1", func(t *testing.T) {
		cfg := fakeConfig{}
		err := confInvalidSC1.Assign(&cfg)
		if err == nil {
			t.Errorf("Assign did not return an error when missing a required field")
			return
		}
		switch err.(type) {
		case *InvalidTagError:
			if err.(*InvalidTagError).NameTag == "field_one" {
				return
			}
		}
		t.Errorf("Assign returned an unexpected error: %s", err)
	})
}

{'fraction_non_alphanumeric': 0.14776245426400225, 'fraction_numerical': 0.010976639459611595, 'mean_word_length': 3.9156293222683263, 'pattern_counts': {'":': 8, '<': 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': '493162', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1255, 'n_words': 324}