github.com/afxcn/moby@v1.13.1/cliconfig/configfile/file_test.go (about)

     1  package configfile
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/docker/api/types"
     7  )
     8  
     9  func TestEncodeAuth(t *testing.T) {
    10  	newAuthConfig := &types.AuthConfig{Username: "ken", Password: "test"}
    11  	authStr := encodeAuth(newAuthConfig)
    12  	decAuthConfig := &types.AuthConfig{}
    13  	var err error
    14  	decAuthConfig.Username, decAuthConfig.Password, err = decodeAuth(authStr)
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  	if newAuthConfig.Username != decAuthConfig.Username {
    19  		t.Fatal("Encode Username doesn't match decoded Username")
    20  	}
    21  	if newAuthConfig.Password != decAuthConfig.Password {
    22  		t.Fatal("Encode Password doesn't match decoded Password")
    23  	}
    24  	if authStr != "a2VuOnRlc3Q=" {
    25  		t.Fatal("AuthString encoding isn't correct.")
    26  	}
    27  }