errors_test.go 1.07 KB
Newer Older
Loïck Bonniot's avatar
Loïck Bonniot committed
1 2 3 4 5 6
package common

import (
	"testing"

	"dfss/dfssp/api"
7
	"github.com/stretchr/testify/assert"
Loïck Bonniot's avatar
Loïck Bonniot committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
)

func TestEvaluateErrorCodeResponse(t *testing.T) {

	success := &api.ErrorCode{
		Code:    api.ErrorCode_SUCCESS,
		Message: "Useless message",
	}

	err := EvaluateErrorCodeResponse(success)
	assert.Equal(t, nil, err)

	warning := &api.ErrorCode{
		Code:    api.ErrorCode_WARNING,
		Message: "Useful message",
	}

	err = EvaluateErrorCodeResponse(warning)
	assert.Equal(t, "Operation succeeded with a warning message: Useful message", err.Error())

	badauth := &api.ErrorCode{
		Code:    api.ErrorCode_BADAUTH,
		Message: "Useless message",
	}

	err = EvaluateErrorCodeResponse(badauth)
	assert.Equal(t, "Authentication error", err.Error())

	other := &api.ErrorCode{
		Code: api.ErrorCode_INTERR,
	}

	err = EvaluateErrorCodeResponse(other)
	assert.Equal(t, "Received error code INTERR", err.Error())

	otherWithMessage := &api.ErrorCode{
		Code:    api.ErrorCode_INVARG,
		Message: "Invalid mail",
	}

	err = EvaluateErrorCodeResponse(otherWithMessage)
49
	assert.Equal(t, "Invalid mail", err.Error())
Loïck Bonniot's avatar
Loïck Bonniot committed
50
}