Skip to content

Commit

Permalink
credentials: don't fail tests early, and use consts
Browse files Browse the repository at this point in the history
- use consts for fixed values in tests
- don't fail tests early if there's more we can test

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed May 27, 2023
1 parent c20f883 commit 14d46ff
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions credentials/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (m *memoryStore) List() (map[string]string, error) {
}

func TestStore(t *testing.T) {
serverURL := "https://index.docker.io/v1/"
const serverURL = "https://index.docker.io/v1/"
creds := &Credentials{
ServerURL: serverURL,
Username: "foo",
Expand All @@ -65,11 +65,11 @@ func TestStore(t *testing.T) {
}

if c.Username != "foo" {
t.Fatalf("expected username foo, got %s\n", c.Username)
t.Errorf("expected username foo, got %s\n", c.Username)
}

if c.Secret != "bar" {
t.Fatalf("expected username bar, got %s\n", c.Secret)
t.Errorf("expected username bar, got %s\n", c.Secret)
}
}

Expand All @@ -89,7 +89,7 @@ func TestStoreMissingServerURL(t *testing.T) {
h := newMemoryStore()

if err := Store(h, in); IsCredentialsMissingServerURL(err) == false {
t.Fatal(err)
t.Error(err)
}
}

Expand All @@ -109,12 +109,12 @@ func TestStoreMissingUsername(t *testing.T) {
h := newMemoryStore()

if err := Store(h, in); IsCredentialsMissingUsername(err) == false {
t.Fatal(err)
t.Error(err)
}
}

func TestGet(t *testing.T) {
serverURL := "https://index.docker.io/v1/"
const serverURL = "https://index.docker.io/v1/"
creds := &Credentials{
ServerURL: serverURL,
Username: "foo",
Expand Down Expand Up @@ -147,16 +147,16 @@ func TestGet(t *testing.T) {
}

if c.Username != "foo" {
t.Fatalf("expected username foo, got %s\n", c.Username)
t.Errorf("expected username foo, got %s\n", c.Username)
}

if c.Secret != "bar" {
t.Fatalf("expected username bar, got %s\n", c.Secret)
t.Errorf("expected username bar, got %s\n", c.Secret)
}
}

func TestGetMissingServerURL(t *testing.T) {
serverURL := "https://index.docker.io/v1/"
const serverURL = "https://index.docker.io/v1/"
creds := &Credentials{
ServerURL: serverURL,
Username: "foo",
Expand All @@ -177,12 +177,12 @@ func TestGetMissingServerURL(t *testing.T) {
w := new(bytes.Buffer)

if err := Get(h, buf, w); IsCredentialsMissingServerURL(err) == false {
t.Fatal(err)
t.Error(err)
}
}

func TestErase(t *testing.T) {
serverURL := "https://index.docker.io/v1/"
const serverURL = "https://index.docker.io/v1/"
creds := &Credentials{
ServerURL: serverURL,
Username: "foo",
Expand All @@ -206,12 +206,12 @@ func TestErase(t *testing.T) {

w := new(bytes.Buffer)
if err := Get(h, buf, w); err == nil {
t.Fatal("expected error getting missing creds, got empty")
t.Error("expected error getting missing creds, got empty")
}
}

func TestEraseMissingServerURL(t *testing.T) {
serverURL := "https://index.docker.io/v1/"
const serverURL = "https://index.docker.io/v1/"
creds := &Credentials{
ServerURL: serverURL,
Username: "foo",
Expand Down Expand Up @@ -244,6 +244,6 @@ func TestList(t *testing.T) {
}
// testing that there is an output
if out.Len() == 0 {
t.Fatalf("expected output in the writer, got %d", 0)
t.Error("expected output in the writer, got 0")
}
}

0 comments on commit 14d46ff

Please sign in to comment.