eintopf.info@v0.13.16/service/status/status_test.go (about)

     1  // Copyright (C) 2022 The Eintopf authors
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    15  
    16  package status_test
    17  
    18  import (
    19  	"testing"
    20  
    21  	"eintopf.info/service/status"
    22  )
    23  
    24  func TestService(t *testing.T) {
    25  	service := status.NewService()
    26  
    27  	status1 := service.Status()
    28  	status2 := service.Status()
    29  	if status1.Uptime >= status2.Uptime {
    30  		t.Error("uptime doesn't increase")
    31  	}
    32  
    33  	service.RequestServed(20)
    34  	service.RequestServed(20)
    35  	service.RequestServed(80)
    36  
    37  	status3 := service.Status()
    38  	if status3.RequestDuration.Min != 20 {
    39  		t.Errorf("min responsetime != 20: %d", status3.RequestDuration.Min)
    40  	}
    41  	if status3.RequestDuration.Max != 80 {
    42  		t.Errorf("max responsetime != 80: %d", status3.RequestDuration.Max)
    43  	}
    44  	if status3.RequestDuration.Avg != 40 {
    45  		t.Errorf("avg responsetime != 40: %d", status3.RequestDuration.Avg)
    46  	}
    47  }