github.com/gramework/gramework@v1.8.1-0.20231027140105-82555c9057f5/new_test.go (about)

     1  // Copyright 2017-present Kirill Danshin and Gramework contributors
     2  // Copyright 2019-present Highload LTD (UK CN: 11893420)
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  
    11  package gramework
    12  
    13  import (
    14  	"testing"
    15  
    16  	"github.com/stretchr/testify/assert"
    17  )
    18  
    19  func TestNewShouldNeverReturnNil(t *testing.T) {
    20  	app := New()
    21  	if app == nil {
    22  		t.Log("App is nil!")
    23  		t.FailNow()
    24  		return
    25  	}
    26  	if app.defaultRouter == nil {
    27  		t.Log("App Router is nil!")
    28  		t.FailNow()
    29  		return
    30  	}
    31  	if app.Logger == nil {
    32  		t.Log("App Logger is nil!")
    33  		t.FailNow()
    34  		return
    35  	}
    36  	if app.domainListLock == nil {
    37  		t.Log("App domain list lock is nil!")
    38  		t.FailNow()
    39  		return
    40  	}
    41  }
    42  
    43  func TestNewWithName(t *testing.T) {
    44  	newApp := func(n string) {
    45  		app := New(OptAppName(n))
    46  		assert.Equal(t, n, app.name)
    47  		assert.Equal(t, n, app.serverBase.Name)
    48  	}
    49  	t.Run("DefaultName", func(t *testing.T) {
    50  		newApp(DefaultAppName)
    51  	})
    52  	t.Run("CustomName", func(t *testing.T) {
    53  		newApp("test_app")
    54  	})
    55  	t.Run("EmptyName", func(t *testing.T) {
    56  		newApp("")
    57  	})
    58  }
    59  
    60  func TestNewWithoutName(t *testing.T) {
    61  	app := New()
    62  	assert.Equal(t, DefaultAppName, app.name)
    63  	assert.Equal(t, DefaultAppName, app.serverBase.Name)
    64  }