💾 Archived View for source.community › ckaznocha › gemini › raw › main › status_test.go captured on 2024-05-10 at 11:20:07.

View Raw

More Information

⬅️ Previous capture (2021-12-17)

-=-=-=-=-=-=-

package gemini_test

import (
	"reflect"
	"testing"

	"source.community/ckaznocha/gemini"
)

func TestCategory_ToCode(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name string
		c    gemini.StatusCodeCategory
		want gemini.StatusCode
	}{
		{
			name: "",
			c:    gemini.StatusCategoryPermanentFailure,
			want: gemini.StatusPermanentFailure,
		},
		{
			name: "",
			c:    10,
			want: 0,
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			if got := tt.c.ToCode(); got != tt.want {
				t.Errorf("Category.ToCode() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestCategory_String(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name string
		c    gemini.StatusCodeCategory
		want string
	}{
		{
			name: "",
			c:    gemini.StatusCategoryPermanentFailure,
			want: "PERMANENT FAILURE",
		},
		{
			name: "",
			c:    10,
			want: "StatusCodeCategory(10)",
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			if got := tt.c.String(); got != tt.want {
				t.Errorf("Category.String() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestCode_MarshalText(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name    string
		want    []byte
		c       gemini.StatusCode
		wantErr bool
	}{
		{
			name:    "",
			want:    []byte("59"),
			c:       gemini.StatusBadRequest,
			wantErr: false,
		},
		{
			name:    "",
			want:    []byte("00"),
			c:       100,
			wantErr: false,
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			got, err := tt.c.MarshalText()
			if (err != nil) != tt.wantErr {
				t.Errorf("Code.MarshalText() error = %v, wantErr %v", err, tt.wantErr)

				return
			}
			if !reflect.DeepEqual(got, tt.want) {
				t.Errorf("Code.MarshalText() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestCode_ToCategory(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name string
		c    gemini.StatusCode
		want gemini.StatusCodeCategory
	}{
		{
			name: "",
			c:    gemini.StatusBadRequest,
			want: gemini.StatusCategoryPermanentFailure,
		},
		{
			name: "",
			c:    100,
			want: gemini.StatusCategoryUndefined,
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			if got := tt.c.ToCategory(); got != tt.want {
				t.Errorf("Code.ToCategory() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestCode_Description(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name string
		want string
		c    gemini.StatusCode
	}{
		{
			name: "",
			want: "The server was unable to parse the client's request, presumably due to a malformed request.",
			c:    gemini.StatusBadRequest,
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			if got := tt.c.Description(); got != tt.want {
				t.Errorf("Code.Description() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestCode_String(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name string
		want string
		c    gemini.StatusCode
	}{
		{
			name: "",
			want: "INPUT",
			c:    gemini.StatusCategoryInput.ToCode(),
		},
		{
			name: "",
			want: "SUCCESS",
			c:    gemini.StatusCategorySuccess.ToCode(),
		},
		{
			name: "",
			want: "REDIRECT - TEMPORARY",
			c:    gemini.StatusCategoryRedirect.ToCode(),
		},
		{
			name: "",
			want: "TEMPORARY FAILURE",
			c:    gemini.StatusCategoryTemporaryFailure.ToCode(),
		},
		{
			name: "",
			want: "PERMANENT FAILURE",
			c:    gemini.StatusCategoryPermanentFailure.ToCode(),
		},
		{
			name: "",
			want: "CLIENT CERTIFICATE REQUIRED",
			c:    gemini.StatusCategoryClientCertificateRequired.ToCode(),
		},
		{
			name: "",
			want: "StatusCode(0)",
			c:    0,
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			if got := tt.c.String(); got != tt.want {
				t.Errorf("Code.String() = %v, want %v", got, tt.want)
			}
		})
	}
}