github.com/SupersunnySea/draft@v0.16.0/pkg/builder/registry_test.go (about)

     1  package builder
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestFromAuthConfigToken(t *testing.T) {
     9  	var authConfigTests = []struct {
    10  		input    string
    11  		fail     bool
    12  		expected *DockerConfigEntryWithAuth
    13  	}{
    14  		{"", true, nil},
    15  		{"badbase64input", true, nil},
    16  		{"e30K", false, &DockerConfigEntryWithAuth{}},
    17  		{"eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCJ9Cg==", false, &DockerConfigEntryWithAuth{Username: "username", Password: "password"}},
    18  		{"eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCIsImVtYWlsIjoiZW1haWwiLCJhdXRoIjoiYXV0aCJ9Cg==", false, &DockerConfigEntryWithAuth{Username: "username", Password: "password", Email: "email", Auth: "auth"}},
    19  		{"eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCIsImVtYWlsIjoiZW1haWwiLCJhdXRoIjoiYXV0aCIsInNlcnZlcmFkZHJlc3MiOiJodHRwOi8vc2VydmVyYWRkcmVzcy5jb20ifQo=", false, &DockerConfigEntryWithAuth{Username: "username", Password: "password", Email: "email", Auth: "auth"}},
    20  	}
    21  
    22  	for _, tt := range authConfigTests {
    23  		actual, err := FromAuthConfigToken(tt.input)
    24  		if tt.fail && err == nil {
    25  			t.Errorf("FromAuthConfigToken(%s) was expected to fail", tt.input)
    26  		} else if !tt.fail && err != nil {
    27  			t.Errorf("FromAuthConfigToken(%s) was not expected to fail", tt.input)
    28  		}
    29  		if !reflect.DeepEqual(actual, tt.expected) {
    30  			t.Errorf("FromAuthConfigToken(%s): expected output differs from actual", tt.input)
    31  		}
    32  	}
    33  }