github.com/drone/runner-go@v1.12.0/registry/auths/encode_test.go (about)

     1  // Copyright 2019 Drone.IO Inc. All rights reserved.
     2  // Use of this source code is governed by the Polyform License
     3  // that can be found in the LICENSE file.
     4  
     5  package auths
     6  
     7  import (
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/drone/drone-go/drone"
    12  )
    13  
    14  func TestEncode(t *testing.T) {
    15  	endpoint := "docker.io"
    16  	username := "octocat"
    17  	password := "correct-horse-battery-staple"
    18  	registry := &drone.Registry{
    19  		Username: username,
    20  		Password: password,
    21  		Address:  endpoint,
    22  	}
    23  	got := Encode(registry, registry, registry)
    24  	want := `{"auths":{"docker.io":{"auth":"b2N0b2NhdDpjb3JyZWN0LWhvcnNlLWJhdHRlcnktc3RhcGxl"}}}`
    25  	if strings.TrimSpace(got) != strings.TrimSpace(want) {
    26  		t.Errorf("Unexpected encoding: %q want %q", got, want)
    27  	}
    28  }