<commit_before>package registry

import (
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"

	"github.com/docker/docker/cliconfig"
)

func TestEncodeAuth(t *testing.T) {
	newAuthConfig := &cliconfig.AuthConfig{Username: "ken", Password: "<PASSWORD>", Email: "<EMAIL>"}
	authStr := cliconfig.EncodeAuth(newAuthConfig)
	decAuthConfig := &cliconfig.AuthConfig{}
	var err error
	decAuthConfig.Username, decAuthConfig.Password, err = cliconfig.DecodeAuth(authStr)
	if err != nil {
		t.Fatal(err)
	}
	if newAuthConfig.Username != decAuthConfig.Username {
		t.Fatal("Encode Username doesn't match decoded Username")
	}
	if newAuthConfig.Password != decAuthConfig.Password {
		t.Fatal("Encode Password doesn't match decoded Password")
	}
	if authStr != "a2VuOnRlc3Q=" {
		t.Fatal("AuthString encoding isn't correct.")
	}
}

func setupTempConfigFile() (*cliconfig.ConfigFile, error) {
	root, err := ioutil.TempDir("", "docker-test-auth")
	if err != nil {
		return nil, err
	}
	root = filepath.Join(root, cliconfig.CONFIGFILE)
	configFile := cliconfig.NewConfigFile(root)

	for _, registry := range []string{"testIndex", INDEXSERVER} {
		configFile.AuthConfigs[registry] = cliconfig.AuthConfig{
			Username: "docker-user",
			Password: "<PASSWORD>",
			Email:    "<EMAIL>",
		}
	}

	return configFile, nil
}

func TestSameAuthDataPostSave(t *testing.T) {
	configFile, err := setupTempConfigFile()
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(configFile.Filename())

	err = configFile.Save()
	if err != nil {
		t.Fatal(err)
	}
<commit_msg>golint for cliconfig<commit_after>package registry

import (
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"

	"github.com/docker/docker/cliconfig"
)

func TestEncodeAuth(t *testing.T) {
	newAuthConfig := &cliconfig.AuthConfig{Username: "ken", Password: "<PASSWORD>", Email: "<EMAIL>"}
	authStr := cliconfig.EncodeAuth(newAuthConfig)
	decAuthConfig := &cliconfig.AuthConfig{}
	var err error
	decAuthConfig.Username, decAuthConfig.Password, err = cliconfig.DecodeAuth(authStr)
	if err != nil {
		t.Fatal(err)
	}
	if newAuthConfig.Username != decAuthConfig.Username {
		t.Fatal("Encode Username doesn't match decoded Username")
	}
	if newAuthConfig.Password != decAuthConfig.Password {
		t.Fatal("Encode Password doesn't match decoded Password")
	}
	if authStr != "a2VuOnRlc3Q=" {
		t.Fatal("AuthString encoding isn't correct.")
	}
}

func setupTempConfigFile() (*cliconfig.ConfigFile, error) {
	root, err := ioutil.TempDir("", "docker-test-auth")
	if err != nil {
		return nil, err
	}
	root = filepath.Join(root, cliconfig.ConfigFileName)
	configFile := cliconfig.NewConfigFile(root)

	for _, registry := range []string{"testIndex", INDEXSERVER} {
		configFile.AuthConfigs[registry] = cliconfig.AuthConfig{
			Username: "docker-user",
			Password: "<PASSWORD>",
			Email:    "<EMAIL>",
		}
	}

	return configFile, nil
}

func TestSameAuthDataPostSave(t *testing.T) {
	configFile, err := setupTempConfigFile()
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(configFile.Filename())

	err = configFile.Save()
	if err != nil {
		t.Fatal(err)
	}

{'fraction_non_alphanumeric': 0.14345991561181434, 'fraction_numerical': 0.0012982797792924375, 'mean_word_length': 4.826086956521739, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2593579', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1087, 'n_words': 224}